Select to view content in your preferred language

Using the Esri Runtime in a Class Library

2328
14
12-04-2019 07:54 AM
MichaelHamsa
Regular Contributor

Hello,

We have developed some .NET 4.7.2 Class Libraries and are using the Esri Runtime SDK in those class libraries. These class libraries get compiled into DLLs and those DLLs are used in other client applications. When the code in these class libraries attempts to open a mobile map package (MobileMapPackage.OpenAsync), it seems like something is happening in the Runtime, like an unhandled exception of some sort, and the mobile map packages do not load. We've wrapped the call in a try/catch but no exceptions are thrown. If I try to add another call before MobileMapPackage.OpenAsync, like MobileMapPackage.IsDirectReadSupportedAsync, we do get an exception - Unable to load runtimecore.dll - even though all of the ArcGISRuntime folders, assemblies and dependencies are in the correct location under the bin folder.

I'm really at a loss right now. I've tried the things I know and I'm not having any luck.

I've attached a simple Visual Studio 2019 solution that you can use to reproduce the problem. You may need to "Restore NuGet Packages", once you open the solution. Also, The file name for the mobile map package is hard-coded, so you will need to change that code before you run the app Otherwise, it should be all ready to go. You can step through the code and notice that once you get the MobileMapPackage OpenAsync or IsDirectReadSupportedAsync you will start running into problems.

Thanks,

Mike Hamsa

0 Kudos
14 Replies
MichaelBranscomb
Esri Frequent Contributor

HI,

Thanks for attaching the repro. Have you already tried setting the ArcGISRuntimeEnvironment.InstallPath Property ?

Cheers

Mike

0 Kudos
dotMorten_esri
Esri Notable Contributor

Also calling ArcGISRuntimeEnvironment.Initialize() at app startup should give you a much better error.
When deploying the plugin make sure the native resources (ie the ArcGISRuntime100.x folder) is located next to the executable (ie not next to the Esri.ArcGISRuntime.dll assembly). Otherwise use the InstallPath Mike is proposing.

0 Kudos
dotMorten_esri
Esri Notable Contributor

...here's the error I get if I call Initialize() in your reproducer:

Error initializing ArcGISRuntimeEnvironment. Unable to find ArcGISRuntime deployment folder. Ensure there is a folder named "arcgisruntime100.6" in the same folder as your application executable, or set ArcGISRuntimeEnvironment.InstallPath to reference an alternative location. The deployment folder must contain sub-folders matching the process architecture of your application.

Then I realize it's not even deploying the native files. The quick fix is to migrate away from Packages.config:

Once you do that, your app should run just fine.

0 Kudos
MichaelHamsa
Regular Contributor

Morten,

Yeah, just noticed that here as well. That’s a problem with the Post Build Event on the class library project in that Solution and it isn’t copying all of the runtime folders to the correct output directory. You can probably copy those folders over manually just to get that solution running and reproduce the runtime problem. Or I can upload a new solution with that Post Build Event fixed.

However, I just fixed the post build event here and tried to set the InstallPath AND call Initialize before doing anything else and I’m still having very similar problems.

Mike Hamsa

Chief Technology Officer - GeoSpatial Innovations, Inc.

P: 512-982-6735

0 Kudos
MichaelHamsa
Regular Contributor

Morten,

I just wanted to follow up and make sure you understood that I’m still seeing the problem even if I set the InstallPath and call Initialize in that sample application – even with the native files deployed to the correct location.

Mike Hamsa

Chief Technology Officer - GeoSpatial Innovations, Inc.

P: 512-982-6735

0 Kudos
MichaelHamsa
Regular Contributor

Morten,

 

Also, it looks like migrating away from Packages.config, as you suggested, did not resolve the problem.

0 Kudos
MichaelHamsa
Regular Contributor

Morten,

Here's the debug output - you can see that RuntimeCoreNet.dll and runtimecore.dll are both getting loaded, however execution still stops unexpectable when the call to MobileMapPackage.OpenAsync is made from the class library - as if something is going on the ArcGIS Runtime that isn't expected.

I hope you will take another look at it and see if you can figure out what's going on.

0 Kudos
dotMorten_esri
Esri Notable Contributor

If initialize succeeds and you see the assemblies load, that isn't the issue any longer. What exception is .NET throwing in this case?
Also does it work if you do a "normal" .NET application and execute the same code?

0 Kudos
MichaelHamsa
Regular Contributor

Morten,

That’s kind of the issue – it really doesn’t throw an exception. I’ve got the call to MobileMapPackage.OpenAsync wrapped in a try/catch but when you step over that line with the debugger, execution jumps completely out of the method. It’s a very strange issue; that’s why I wanted to try to put that little app together so you can try it for yourself.

As for your other question, yes it does work in a more conventional setting. I have a WFP app that makes the same the call to MobileMapPackage.OpenAsync and it is successful. In that WPF app I’ve even referenced the same class library and when I make the call to MobileMapPackage.OpenAsync in the WFP app it works, then on the next line I call into the OpenMap function in that class library, which call also MobileMapPackage.OpenAsync, and it fails the same way.

I really think it you ran the app I attached and stepped though the code you’d get a better idea about what’s going on.

Mike Hamsa

Chief Technology Officer - GeoSpatial Innovations, Inc.

P: 512-982-6735

0 Kudos