MvvmCross: Failed to resolve type MvvmCross.ViewModels.IMvxAppStart

Steps to reproduce 📜

Xamarin caused by: android.runtime.JavaProxyThrowable: MvvmCross.Exceptions.MvxIoCResolveException: Failed to resolve type MvvmCross.ViewModels.IMvxAppStart
MvvmCross.IoC.MvxIoCContainer.Resolve(Type t)<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.IoC.MvxIoCContainer.Resolve<T>()<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.IoC.MvxIoCProvider.Resolve<T>()<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.Mvx.Resolve<TService>()<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.Platforms.Android.Views.MvxActivityViewExtensions.OnViewDestroy(IMvxAndroidView androidView)<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.Platforms.Android.Views.MvxActivityAdapter.EventSourceOnDestroyCalled(object sender, EventArgs eventArgs)<a1ab21c493b64a15919bccd6a6fb7be2>:0
at (wrapper delegate-invoke) <Module>.invoke_void_object_EventArgs(object,System.EventArgs)
MvvmCross.Base.MvxDelegateExtensions.Raise(EventHandler eventHandler, object sender)<a1ab21c493b64a15919bccd6a6fb7be2>:0
MvvmCross.Droid.Support.V7.AppCompat.EventSource.MvxEventSourceAppCompatActivity.OnDestroy()<a463012b56d64d1f9cc54a527e8dd780>:0
MvvmCross.Droid.Support.V7.AppCompat.MvxAppCompatActivity.OnDestroy()<a463012b56d64d1f9cc54a527e8dd780>:0
Android.App.Activity.n_OnDestroy(IntPtr jnienv, IntPtr native__this)<8e97598d39014e64a9b297bda6092daf>:0
at (wrapper dynamic-method) System.Object.51564007-77ee-4aca-b000-e0c439692f3c(intptr,intptr)
mvvmcross.droid.support.v7.appcompat.MvxAppCompatActivity.n_onDestroy(Native Method)
mvvmcross.droid.support.v7.appcompat.MvxAppCompatActivity.onDestroy()MvxAppCompatActivity.java:61
android.app.Activity.performDestroy()Activity.java:7462
android.app.Instrumentation.callActivityOnDestroy()Instrumentation.java:1255
android.app.ActivityThread.performDestroyActivity()ActivityThread.java:4590
android.app.ActivityThread.handleDestroyActivity()ActivityThread.java:4621
android.app.ActivityThread.-wrap5()Unknown Source:0
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1757
android.os.Handler.dispatchMessage()Handler.java:105
android.os.Looper.loop()Looper.java:164
android.app.ActivityThread.main()ActivityThread.java:6938
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.Zygote$MethodAndArgsCaller.run()Zygote.java:327
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1374

 public SplashScreen() : base(Resource.Layout.SplashScreen)
 {
        this.RegisterSetupType<Setup>();
 }

 protected override void RunAppStart(Bundle bundle)
 {
        var starter = MvvmCross.Mvx.Resolve<IMvxAppStart>();
        starter.Start(model);
  }

Configuration 🔧

Version: MvvmCross 6.0.0

Platform: Android 5.1.1, 8.0.0 SAMSUNG SM-G5500 SAMSUNG SM-G950F

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I haven’t permission to push and create PR. How can I get them? Just change from at MvxSplashScreenAppCompatActivity and MvxSplashScreenActivity

protected virtual async Task RunAppStartAsync(Bundle bundle)
        {
            var startup = Mvx.IoCProvider.Resolve<IMvxAppStart>();
            if (!startup.IsStarted)
                await startup.StartAsync(GetAppStartHint(bundle));
        }

to

protected virtual async Task RunAppStartAsync(Bundle bundle)
        {
            if (Mvx.IoCProvider.TryResolve<IMvxAppStart>(out IMvxAppStart startup))
            {
                if (!startup.IsStarted)
                    await startup.StartAsync(GetAppStartHint(bundle));
            }
        }

Can anybody create this PR?

As I understand, SplashScreen uses Mvx.Resolve<IMvxAppStart> in several places, fix was made just for one place. One workaround - override RunAppStart in SplashScreen

protected override void RunAppStart(Bundle bundle)
       {
           if (Mvx.TryResolve<IMvxAppStart>(out IMvxAppStart mvxAppStart))
           {
               if (mvxAppStart.IsStarted)
                   return;
               mvxAppStart.Start(this.GetAppStartHint((object) bundle));
           }
       }

Yes, I think that should be sufficient to resolve this issue. @haohighview would you be kind enough to raise a PR based on the suggestion made by @nmilcoff