从MvvmCross 4迁移到5后,Xamarin iOS在启动时崩溃

时间:2017-10-25 09:25:10

标签: ios xamarin xamarin.ios mvvmcross

将MvvmCross从版本4升级到5.1.1后,我在入口点获取了一个TargetInvocationException(UIApplication.Main(...))。这是班级:

using UIKit;

namespace sample
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main(args, null, "AppDelegate");
        }
    }
}

这是抛出的异常:

Unhandled Exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

2017-10-25 11:12:34.931 SampleAppMobileiOS[5351:568000] 
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at MvvmCross.Platform.Mvx.Resolve[TService] () [0x00006] in <54d9eb77c4d448d4bc5e7c7a5cdd0a97>:0 
  at MvvmCross.iOS.Views.MvxBindingViewControllerAdapter.HandleViewDidDisappearCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1[T] e) [0x00029] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxBindingViewControllerAdapter.cs:26 
  at MvvmCross.iOS.Views.MvxViewControllerAdaptingExtensions.AdaptForBinding (MvvmCross.Platform.iOS.Views.IMvxEventSourceViewController view) [0x00008] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxViewControllerAdaptingExtensions.cs:17 
  at MvvmCross.iOS.Views.MvxViewController..ctor (System.IntPtr handle) [0x00009] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxViewCon
troller.cs:28 
  at SampleApp.Mobile.iOS.BaseViewController..ctor (System.IntPtr handle) [0x0008c] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Views\BaseViewController.cs:35 
  at SampleApp.Mobile.iOS.MainView..ctor (System.IntPtr handle) [0x00000] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Views\MainView.cs:16 
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:661 
   --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/c
lass/corlib/System.Reflection/MonoMethod.cs:667 
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:652 
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:680 
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62 
  at ObjCRuntime.Runtime.ConstructNSObject[T] (System.IntPtr ptr, System.Type type, Ob
jCRuntime.Runtime+MissingCtorResolution missingCtorResolution) [0x0003e] in <512590c9cb4447d89974aa2a90fea66f>:0 
  at ObjCRuntime.Runtime.ConstructNSObject (System.IntPtr ptr, System.IntPtr klass, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution) [0x00013] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:981 
  at ObjCRuntime.Runtime.GetNSObject (System.IntPtr ptr, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution, System.Boolean evenInFinalizerQueue) [0x00022] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:1099 
  at ObjCRuntime.Runtime.TryGetOrConstructNSObjectWrapped (System.IntPtr ptr) [0x00000] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:648 
  at ObjCRuntime.Runtime.try_get_or_construct_nsobject (System.IntPtr obj, System.Int32& exception_gchandle) [0x00003] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/runtime/Delegates.
generated.cs:342 
--- End of stack trace from previous location where exception was thrown ---
  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/data/lanes/5489/1b460cb9/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at SampleApp.Mobile.iOS.Application.Main (System.String[] args) [0x00001] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Main.cs:12 
2017-10-25 11:12:34.938 SampleAppMobileiOS[5351:568000] Unhandled managed exception:
Exception has been thrown by the target of an invocation. (System.Reflection.TargetInvocationException)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00012] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:667 
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:652 
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Library/Frameworks/Xamarin.iOS.framewor
k/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:680 
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62 
  at ObjCRuntime.Runtime.ConstructNSObject[T] (System.IntPtr ptr, System.Type type, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution) [0x0003e] in <512590c9cb4447d89974aa2a90fea66f>:0 
  at ObjCRuntime.Runtime.ConstructNSObject (System.IntPtr ptr, System.IntPtr klass, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution) [0x00013] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:981 
  at ObjCRuntime.Runtime.GetNSObject (System.IntPtr ptr, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution, System.Boolean evenInFinalizerQueue) [0x00022] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:1099 

 at ObjCRuntime.Runtime.TryGetOrConstructNSObjectWrapped (System.IntPtr ptr) [0x00000] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:648 
  at ObjCRuntime.Runtime.try_get_or_construct_nsobject (System.IntPtr obj, System.Int32& exception_gchandle) [0x00003] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/runtime/Delegates.generated.cs:342 
--- End of stack trace from previous location where exception was thrown ---
  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/data/lanes/5489/1b460cb9/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5489/1b460cb9/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at Oase
n.DigitaleRotonde.Mobile.iOS.Application.Main (System.String[] args) [0x00001] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Main.cs:12 
 --- inner exception ---
Object reference not set to an instance of an object (System.NullReferenceException)
  at MvvmCross.Platform.Mvx.Resolve[TService] () [0x00006] in <54d9eb77c4d448d4bc5e7c7a5cdd0a97>:0 
  at MvvmCross.iOS.Views.MvxBindingViewControllerAdapter.HandleViewDidDisappearCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1[T] e) [0x00029] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxBindingViewControllerAdapter.cs:26 
  at MvvmCross.iOS.Views.MvxViewControllerAdaptingExtensions.AdaptForBinding (MvvmCross.Platform.iOS.Views.IMvxEventSourceViewController view) [0x00008] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxViewControllerAdaptingExtensions.cs:17 
  at MvvmCross.iOS.Views.MvxViewController..ctor (System.IntPtr handle) [0x00009] in C:\projects\mvvmcross\MvvmCross\iOS\iOS\Views\MvxViewCo
ntroller.cs:28 
  at SampleApp.Mobile.iOS.BaseViewController..ctor (System.IntPtr handle) [0x0008c] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Views\BaseViewController.cs:35 
  at SampleApp.Mobile.iOS.MainView..ctor (System.IntPtr handle) [0x00000] in D:\Sample_Mobile\SampleApp.Mobile\SampleApp.Mobile.iOS\Views\MainView.cs:16 
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.4.0.93/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:661 
2017-10-25 11:12:34.939 SampleAppMobileiOS[5351:568000] critical: Stacktrace:

2017-10-25 11:12:34.939 SampleAppMobileiOS[5351:568000] critical: 
Native stacktrace:
2017-10-25 11:12:34.953 SampleAppMobileiOS[5351:568000] critical:   0   SampleAppMobileiOS       0x0000000101491b2c SampleAppMobileiOS + 21240620
2017-10-25 11:12:34.954 SampleAppMobileiOS[5351:568000] critical:   1   libsystem_platform.dylib            0x0000000189a5531c _sigtramp + 52
2017-10-25 11:12:34.954 SampleAppMobileiOS[5351:568000] critical:   2   libsystem_pthread.dylib             0x0000000189a5b264 pthread_kill + 112
2017-10-25 11:12:34.955 SampleAppMobileiOS[5351:568000] critical:   3   libsystem_c.dylib                   0x00000001899059c4 abort + 140
2017-10-25 11:12:34.955 SampleAppMobileiOS[5351:568000] critical:   4   SampleAppMobileiOS       0x00000001015963dc xamarin_get_block_descriptor + 8260
2017-10-25 11:12:34.956 SampleAppMobileiOS[5351:568000] critical:   5   SampleAppMobileiOS       0x00000001014cf4ec mono_pmip + 216852
2017-10-25 11:12:34.956 SampleAppMobileiOS[5351:568000] critical:   6   SampleAppMobileiOS       0x0000000101491928 SampleAppMobileiOS + 21240104
2017-10-25 11:12:34.957 SampleAppMobileiOS[5351:568000] critical:   7   SampleAppMobileiOS       0x0000000101490738 SampleAppMobileiOS + 21235512
2017-10-25 11:12:34.958 SampleAppMobileiOS[5351:568000] critical:   8   SampleAppMobileiOS       0x0000000101488d1c SampleAppMobileiOS + 21204252
2017-10-25 11:12:34.958 SampleAppMobileiOS[5351:568000] critical:   9   SampleAppMobileiOS       0x0000000100364e68 SampleAppMobileiOS + 3231336
2017-10-25 11:12:34.959 SampleAppMobileiOS[5351:568000] critical:   10  SampleAppMobileiOS       0x0000000101596130 xamarin_get_block_descriptor + 7576
2017-10-25 11:12:34.960 SampleAppMobileiOS[5351:568000] critical:   11  SampleAppMobileiOS       0x0000000101595fb0 xamarin_get_block_descriptor + 7192
2017-10-25 11:12:34.960 SampleAppMobileiOS[5351:568000] critical:   12  SampleAppMobileiOS       0x0000000100062400 SampleAppMobileiOS + 74752
2017-10-25 11:12:34.961 SampleAppMobileiOS[5351:568000] critical:   13  SampleAppMobileiOS       0x000000010006220c SampleAppMobileiOS + 74252
2017-10-25 11:12:34.961 SampleAppMobileiOS[5351:568000] critical:   14  Foundation                          0x000000018b3ab64c <redacted> + 272
2017-10-25 11:12:34.962 SampleAppMobileiOS[5351:568000] critical:   15  UIKit                               0x0000000190e2c2fc <redacted> + 104
2017-10-25 11:12:34.962 SampleAppMobileiOS[5351:568000] critical:   16  UIKit                               0x0000000190fd00d8 <redacted> + 124
2017-10-25 11:12:34.963 SampleAppMobileiOS[5351:568000] critical:   17  CoreFoundation                      0x000000018a8b7fac <redacted> + 232
2017-10-25 11:12:34.963 SampleAppMobileiOS[5351:568000] critical:   18  UIKit                               0x0000000190fceacc <redacted> + 1696
2017-10-25 11:12:34.964 SampleAppMobileiOS[5351:568000] critical:   19  UIKit                               0x0000000190e2f2d4 <redacted> + 372
2017-10-25 11:12:34.964 SampleAppMobileiOS[5351:568000] critical:   20  UIKit                               0x0000000190bf946c <redacted> + 176
2017-10-25 11:12:34.965 SampleAppMobileiOS[5351:568000] critical:   21  UIKit                               0x0000000190ac7b68 <redacted> + 180
2017-10-25 11:12:34.965 SampleAppMobileiOS[5351:568000] critical:   22  UIKit                               0x0000000190b7fff0 <redacted> + 72
2017-10-25 11:12:34.966 SampleAppMobileiOS[5351:568000] critical:   23  UIKit                               0x0000000190b7fec8 <redacted> + 416
2017-10-25 11:12:34.966 SampleAppMobileiOS[5351:568000] critical:   24  UIKit                               0x0000000190b7f1f8 <redacted> + 144
2017-10-25 11:12:34.966 SampleAppMobileiOS[5351:568000] critical:   25  UIKit                               0x0000000190b7ec2c <redacted> + 856
2017-10-25 11:12:34.967 SampleAppMobileiOS[5351:568000] critical:   26  UIKit                               0x0000000190b7e7e0 <redacted> + 64
2017-10-25 11:12:34.967 SampleAppMobileiOS[5351:568000] critical:   27  UIKit                               0x0000000190b7e744 <redacted> + 188
2017-10-25 11:12:34.967 SampleAppMobileiOS[5351:568000] critical:   28  UIKit                               0x0000000190ac507c <redacted> + 1200
2017-10-25 11:12:34.968 SampleAppMobileiOS[5351:568000] critical:   29  QuartzCore                          0x000000018dcb5274 <redacted> + 148
2017-10-25 11:12:34.968 SampleAppMobileiOS[5351:568000] critical:   30  QuartzCore                          0x000000018dca9de8 <redacted> + 292
2017-10-25 11:12:34.968 SampleAppMobileiOS[5351:568000] critical:   31  QuartzCore                          0x000000018dca9ca8 <redacted> + 32
2017-10-25 11:12:34.969 SampleAppMobileiOS[5351:568000] critical:   32  QuartzCore                          0x000000018dc2534c <redacted> + 252
2017-10-25 11:12:34.969 SampleAppMobileiOS[5351:568000] critical:   33  QuartzCore                          0x000000018dc4c3ac <redacted> + 504
2017-10-25 11:12:34.969 SampleAppMobileiOS[5351:568000] critical:   34  QuartzCore                          0x000000018dc4ce78 <redacted> + 120
2017-10-25 11:12:34.969 SampleAppMobileiOS[5351:568000] critical:   35  CoreFoundation                      0x000000018a9449a8 <redacted> + 32
2017-10-25 11:12:34.970 SampleAppMobileiOS[5351:568000] critical:   36  CoreFoundation                      0x000000018a942630 <redacted> + 372
2017-10-25 11:12:34.970 SampleAppMobileiOS[5351:568000] critical:   37  CoreFoundation                      0x000000018a872dc4 CFRunLoopRunSpecific + 456
2017-10-25 11:12:34.970 SampleAppMobileiOS[5351:568000] critical:   38  UIKit                               0x0000000190b32384 <redacted> + 652
2017-10-25 11:12:34.971 SampleAppMobileiOS[5351:568000] critical:   39  UIKit                               0x0000000190b2d058 UIApplicationMain + 208
2017-10-25 11:12:34.971 SampleAppMobileiOS[5351:568000] critical:   40  SampleAppMobileiOS       0x00000001004552b0 SampleAppMobileiOS + 4215472
2017-10-25 11:12:34.971 SampleAppMobileiOS[5351:568000] critical:   41  SampleAppMobileiOS       0x00000001003fbbdc SampleAppMobileiOS + 3849180
2017-10-25 11:12:34.972 SampleAppMobileiOS[5351:568000] critical:   42  SampleAppMobileiOS       0x00000001003fbb9c SampleAppMobileiOS + 3849116
2017-10-25 11:12:34.972 SampleAppMobileiOS[5351:568000] critical:   43  SampleAppMobileiOS       0x0000000100082d10 SampleAppMobileiOS + 208144
2017-10-25 11:12:34.972 SampleAppMobileiOS[5351:568000] critical:   44  SampleAppMobileiOS       0x0000000100334384 SampleAppMobileiOS + 3031940
2017-10-25 11:12:34.973 SampleAppMobileiOS[5351:568000] critical:   45  SampleAppMobileiOS       0x000000010149fc44 mono_pmip + 22124
2017-10-25 11:12:34.973 SampleAppMobileiOS[5351:568000] critical:   46  SampleAppMobileiOS       0x0000000101507454 mono_pmip + 446076
2017-10-25 11:12:34.973 SampleAppMobileiOS[5351:568000] critical:   47  SampleAppMobileiOS       0x0000000101509fc4 mono_pmip + 457196
2017-10-25 11:12:34.974 SampleAppMobileiOS[5351:568000] critical:   48  SampleAppMobileiOS       0x00000001014884fc SampleAppMobileiOS + 21202172
2017-10-25 11:12:34.974 SampleAppMobileiOS[5351:568000] critical:   49  SampleAppMobileiOS       0x00000001015a4074 _Z9__isctypeim + 46228
2017-10-25 11:12:34.974 SampleAppMobileiOS[5351:568000] critical:   50  SampleAppMobileiOS       0x000000010007611c SampleAppMobileiOS + 155932
2017-10-25 11:12:34.975 SampleAppMobileiOS[5351:568000] critical:   51  libdyld.dylib                       0x000000018988159c <redacted> + 4
2017-10-25 11:12:34.975 SampleAppMobileiOS[5351:568000] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
The app has been terminated.
Failed to Stop app:  An error occured on client IDB471022 while executing a reply for topic xvs/idb/4.7.10.22/stop-app
The app has been terminated.

该应用在mvvmcross 4上运行良好,迁移指南没有任何意外:https://www.mvvmcross.com/documentation/upgrading/upgrade-to-mvvmcross-50。我似乎无法调试任何东西。触发的唯一断点是UIApplication.Main,并且step-into很快停止并导致给定的异常。我在哪里开始搜索才能解决这个问题?

2 个答案:

答案 0 :(得分:0)

查看this

IosView.BindingContext = Mvx.Resolve<IMvxBindingContext>();

IosView ViewController投放到IMvxIosView的位置。这表明您的ViewController未实施IMvxIosView。因为在这种情况下它似乎是唯一的null。

答案 1 :(得分:0)

我终于找到了答案。我在项目中包含2个主要版本的MvvmCross。我现在已经将所有内容升级到6.x.x。然后应用程序启动。