我有一个使用 Xamarin iOS 构建的 iOS 应用程序,在加载具有用于 PInvoke 调用的 DllImport 属性的类时崩溃。例外是:
Unhandled managed exception: An exception was thrown by the type initializer for Pazanga.Native.ZzPINVOKE (System.TypeInitializationException)
该应用程序运行良好,但是当本机库的大小增加时开始崩溃。裁剪库的某些部分后它再次工作,但在链接一个新库后它又开始崩溃。崩溃发生在实际调用本机库之前。
这是崩溃后的设备日志:http: //pastebin.com/vW3CMXHq
内部例外是:
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
这是出现在异常中的 SWIGStringHelper 类(由 SWIG 生成):
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);
}
}
关于如何解决这个问题的任何想法?