Search code examples
c#iosxamarinarcgis

App Crash using Hot Restart Xamarin Forms on iOS and the ArcGIS Runtime


Want to check if anyone has had success with the ArcGIS Runtime Xamarin Forms on iOS using Visual Studio hot restart?

I created a new Xamarin Forms app for iOS in Visual Studio and added the following code in AppDelegate.cs

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
  global::Xamarin.Forms.Forms.Init();
  LoadApplication(new App());
  Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize();

  return base.FinishedLaunching(app, options);
}

The app launches and runs fine without the Initialize method on my iPhone. It feels like I'm missing a dependency.

This is the error I get with the Initialize method:

[0:] An error occurred: 'CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory assembly:<unknown assembly> type:<unknown type> member:(null)'. Callstack: '  at (wrapper managed-to-native) RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory(byte[],intptr&)
  at RuntimeCoreNet.GeneratedWrappers.CoreArcGISRuntimeEnvironment.SetInstallDirectory (System.String installPath) <0x138775060 + 0x00010> in <2a33546a5b934b588629d4e33895c554>:0 
  at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.InitNative () <0x1387748c8 + 0x00004> in <2a33546a5b934b588629d4e33895c554>:0 
  at Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize () <0x138774538 + 0x00042> in <2a33546a5b934b588629d4e33895c554>:0 
  at App1.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00013] in C:\Users\Chris\Documents\OnScene Xplorer\App1\App1.iOS\AppDelegate.cs:33 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65 
  at App1.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\Chris\Documents\OnScene Xplorer\App1\App1.iOS\Main.cs:17 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '

Looks like its attempting to make a call into a native method using DllImport per Reflector.

[DllImport("__Internal")]
private static extern void CoreRT_ArcGISRuntimeEnvironment_setInstallDirectory([In, Out, MarshalAs(UnmanagedType.LPArray)] byte[] installPath, out IntPtr outErrorHandle);

I also tried the sample app from ArcGIS and it also fails the same way once I enable hot restart on it.

More info...

The exception being thrown is EntryPointNotFoundException which means that the native call can't be resolved.

I did some sleuthing on my iPhone and found that runtimecore.dll and runtimecorenet.dll are not being copied to the deployment folder. They also do not appear in the bin/Debug folder during build. I believe those 2 dlls are the target of the native calls in Esri.ArcGISRuntime.dll.

So I think I have to figure out how to convince Visual Studio to include those in the iOS build. I do see them being included in my UWP build.

Any ideas for how to fix this?


Solution

  • A while back Microsoft broke support for native .frameworks in hot restart, and the ArcGIS Runtime relies on these, so unfortunately you'll need a Mac to deploy to a device.