2

My Android App is crashing in the production environment, our crash reporting tool is XamarinInsights, it dumps the following stack

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 

I think exception was thrown when I try to resolve and construct MainThreadDispatcher. But I can't understand why.

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

    private void ShowToastMessage(string message, double duration)
    {
            _dispatcher.RequestMainThreadAction(() =>
            { 
                ...
            });
    }
Pavel Chehov
  • 69
  • 1
  • 8

2 Answers2

2

Try to initialize MvvmCross system every time you receive a push because the execution could be done in different context (when app is unloaded) but push notification service is active.

MvvmCross initialization

Community
  • 1
  • 1
Mando
  • 11,414
  • 17
  • 86
  • 167
2

This is a pretty common problem when working with IntentService, or BroadcastReceiver after the process has been restarted. The MvvmCross IoC container is normally setup by your splash screen. The splash screen is not shown in these cases so the Mvx IoC is basically uninitialized. You can fix the problem by ensuring the MvvmCross setup is initialized after you receive the push notification.

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

MvvmCross has MvxIntentService and MvxBroadcastReceiver. If you use these objects then the MvvmCross setup is automatically initialized for you.

Trevor Balcom
  • 3,766
  • 2
  • 32
  • 51