1
votes

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

at (wrapper castclass) System.Object:__castclass_with_cache (object,intptr,intptr) at MvvmCross.Droid.Support.V7.AppCompat.MvxAppCompatActivity1[TViewModel].get_ViewModel () [0x00006] in <76c7f3cdfddd459898d814608e83832e>:0 at AnyNameSpace.BaseActivity1[TViewModel].get_Context () [0x00000] in <5d7ceda804ca4cbe89e187bc8a206872>:0 at AnyNameSpace.BaseActivity`1[TViewModel].OnCreate (Android.OS.Bundle bundle) [0x00015] in <5d7ceda804ca4cbe89e187bc8a206872>:0 at AnyNameSpace.ProfileView.OnCreate (Android.OS.Bundle bundle) [0x00000] in <03e2d64cacc54ebebbfb6133dd9c33ae>:0 at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <6296d3d76c5d4378959a1d9bf7205023>:0 at (wrapper dynamic-method) System.Object:dd3ad951-7481-46d2-860d-a9601d351cd2 (intptr,intptr,intptr)

This is location where exception has thrown

    public class ProfileView : BaseAppActivity<ProfileViewModel>
    {
        protected override void OnCreate(Bundle bundle)
        {
             base.OnCreate(bundle);
             SetContentView(Resource.Layout.ProfileView);
             Title = string.Format("{0} | {1}", Title, Context.Version);
        }
    }

BaseAppActivity: BaseActivity

        protected override void OnCreate(Bundle bundle)
        {
       SupportRequestWindowFeature((int)WindowFeatures.IndeterminateProgress);
        base.OnCreate(bundle);
        RegisterBaseViewReceiver();

        if (Context != null)
        {
            Context.OnLoaded();
        }

And BaseActivity

    public class BaseActivity<TViewModel> : MvxAppCompatActivity<TViewModel>
    where TViewModel : BaseViewModel
    {
         public TViewModel Context
         {
            get
            {
                return (TViewModel)base.ViewModel;
            }
         }
    }

Exception has thrown in

    return (TViewModel)base.ViewModel;

But I can't reproduce this crash in release and debug configuration, I can see this error only in crash reporting system. Any ideas?

1
FYI there was some discussion about this problem on GitHub Issues as well.Trevor Balcom

1 Answers

0
votes

This is a known bug in MvvmCross, caused by an invalid model being taken from the view model cache. Reproduction steps are in the linked GitHub issue.