I have an iOS app built with Xamarin iOS that crashes when loading the class that has DllImport attributes for PInvoke calls. The exception is:
Unhandled managed exception: An exception was thrown by the type initializer for Pazanga.Native.ZzPINVOKE (System.TypeInitializationException)
The app worked fine, but started crashing when the native library grew in size. After cropping some parts of the library it worked again, but after linking a new library it started crashing again. The crash happens before any calls are actually made to the native library.
Here is the device log after the crash: http://pastebin.com/vW3CMXHq
The inner exceptions are:
Aug 23 10:33:40 Outboxs-iPod pazanga[4216] <Warning>: System.TypeInitializationException: An exception was thrown by the type initializer for Pazanga.Native.ZzPINVOKE ---> System.TypeInitializationException: An exception was thrown by the type initializer for SWIGStringHelper ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:CreateString (intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
at (wrapper managed-to-native) object:__icall_wrapper_mono_delegate_to_ftnptr (object)
at (wrapper managed-to-native) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:SWIGRegisterStringCallback_Zz (Pazanga.Native.ZzPINVOKE/SWIGStringHelper/SWIGStringDelegate)
at Pazanga.Native.ZzPINVOKE+SWIGStringHelper..cctor () [0x00017] in /Users/max/Code/pazanga/mobile/ios/bindings/ZzPINVOKE.cs:229
--- End of inner exception stack trace ---
at Pazanga.Native.ZzPINVOKE..cctor () [0x0000a] in /Users/max/Code/pazanga/mobile/ios/bindings/ZzPINVOKE.cs:233
--- End of inner exception stack trace ---
at Pazanga.Native.Zz.locate (System.Byte[] image, image_format format, Int32 width, Int32 height, Int32 x, Int32 y) [0x00009] in /Users/max/Code/pazanga/mobile/ios/bindings/Zz.cs:16
at Pazanga.CaptureDecode.ProcessFrame (System.Byte[] data, Int32 dataWidth, Int32 dataHeight, Boolean isPicture) [0x000cf] in /Users/max/Code/pazanga/mobile/common/CaptureDecode.cs:95
at Pazanga.iOS.CaptureViewController.HandleNewFrame (System.Byte[] data, Int32 width, Int32 height) [0x0003b] in /Users/max/Code/pazanga/mobile/ios/App/CaptureViewController.cs:128
at Pazanga.iOS.CaptureManager.OnNewFrame (System.Byte[] array, Int32 width, Int32 height) [0x00015] in /Users/max/Code/pazanga/mobile/ios/App/CaptureManager.cs:126
at Pazanga.iOS.CaptureManager+OutputDelegate.DidOutputSampleBuffer (MonoTouch.AVFoundation.AVCaptureOutput captureOutput, MonoTouch.CoreMedia.CMSampleBuffer sampleBuffer, MonoTouch.AVFoundation.AVCaptureConnection connection) [0x000c6] in /Users/max/Code/pazanga/mobile/ios/App/CaptureManager.cs:110
Aug 23 10:33:40 Outboxs-iPod pazanga[4216] <Warning>: System.TypeInitializationException: An exception was thrown by the type initializer for SWIGStringHelper ---> System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:CreateString (intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
at (wrapper managed-to-native) object:__icall_wrapper_mono_delegate_to_ftnptr (object)
at (wrapper managed-to-native) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:SWIGRegisterStringCallback_Zz (Pazanga.Native.ZzPINVOKE/SWIGStringHelper/SWIGStringDelegate)
at Pazanga.Native.ZzPINVOKE+SWIGStringHelper..cctor () [0x00017] in /Users/max/Code/pazanga/mobile/ios/bindings/ZzPINVOKE.cs:229
--- End of inner exception stack trace ---
at Pazanga.Native.ZzPINVOKE..cctor () [0x0000a] in /Users/max/Code/pazanga/mobile/ios/bindings/ZzPINVOKE.cs:233
Aug 23 10:33:40 Outboxs-iPod pazanga[4216] <Warning>: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:CreateString (intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
at (wrapper managed-to-native) object:__icall_wrapper_mono_delegate_to_ftnptr (object)
at (wrapper managed-to-native) Pazanga.Native.ZzPINVOKE/SWIGStringHelper:SWIGRegisterStringCallback_Zz (Pazanga.Native.ZzPINVOKE/SWIGStringHelper/SWIGStringDelegate)
at Pazanga.Native.ZzPINVOKE+SWIGStringHelper..cctor () [0x00017] in /Users/max/Code/pazanga/mobile/ios/bindings/ZzPINVOKE.cs:229
And here is the SWIGStringHelper class (generated by SWIG) that appears in the exception:
protected class SWIGStringHelper {
public delegate string SWIGStringDelegate(string message);
static SWIGStringDelegate stringDelegate = new SWIGStringDelegate(CreateString);
[DllImport("__Internal", EntryPoint="SWIGRegisterStringCallback_Zz")]
public static extern void SWIGRegisterStringCallback_Zz(SWIGStringDelegate stringDelegate);
[MonoTouch.MonoPInvokeCallback(typeof(SWIGStringDelegate))]
static string CreateString(string cString) {
return cString;
}
static SWIGStringHelper() {
SWIGRegisterStringCallback_Zz(stringDelegate);
}
}
Any ideas on how to solve this?
To close the loop... It turned out to be a duplicate of bug 14194 (reverse callback using a string).
A TypeInitializationException
was thrown because the exception occurred inside a static constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With