2017-03-01 18 views
2

我的Android應用程序在生產環境崩潰的時候,我們的崩潰報告工具XamarinInsights,它轉儲以下堆棧未能解決的類型IMvxMainThreadDispatcher的參數調度參數創建

at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00066] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0002a] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.Mvx.IocConstruct[T]() [0x00005] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.Mvx+<>c__13`2[TInterface,TType].<LazyConstructAndRegisterSingleton>b__13_0() [0x00000] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+<>c__DisplayClass33_0`1[TInterface].<RegisterSingleton>b__0() [0x00000] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve() [0x00028] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, MvvmCross.Platform.IoC.MvxSimpleIoCContainer+IResolver resolver, System.Object& resolved) [0x00041] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Nullable`1[T] requiredResolverType, System.Object& resolved) [0x0002e] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00011] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.Resolve[T]() [0x00000] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MvvmCross.Platform.Mvx.Resolve[TService]() [0x00005] in <4ddde23419c5494288c799fcdbb0f189>:0 
at MyNamespace.Android.PushNotificationListener.SendNotification (System.String message, MyNamespace.Core.NotificationPayload payload) [0x00137] in <03e2d64cacc54ebebbfb6133dd9c33ae>:0 

我覺得異常被拋出時,我嘗試解決並構造MainThreadDispatcher。但我不明白爲什麼。

private IMvxMainThreadDispatcher _dispatcher = Mvx.Resolve<IMvxMainThreadDispatcher>(); 

    private void ShowToastMessage(string message, double duration) 
    { 
      _dispatcher.RequestMainThreadAction(() => 
      { 
       ... 
      }); 
    } 

回答

2

嘗試每次接收推,因爲執行過程可能會在不同的情況來進行(當應用被卸載),但推送通知服務處於活動狀態時初始化MvvmCross系統。

MvvmCross initialization

2

這與IntentService,或BroadcastReceiver工作時的過程已經重新啓動後是一個相當普遍的問題。 MvvmCross IoC容器通常由您的閃屏設置。這些情況下不會顯示啓動畫面,因此Mvx IoC基本上未初始化。您可以通過確保在收到推送通知後初始化MvvmCross設置來解決問題。

var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this.ApplicationContext); 
setupSingleton.EnsureInitialized(); 

MvvmCross有MvxIntentServiceMvxBroadcastReceiver。如果您使用這些對象,則Mvv​​mCross設置會自動爲您初始化。