I am using MVVMCross for my Xamarin Android application. Sometimes when I navigate from one viewmodel to another I get
System.Collections.Generic.KeyNotFoundException has been thrown
This occurs at base.OnCreate(bundle)
of the following function when a new activity is being created.
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
if (contentResourceId >= 0)
{
SetContentView(contentResourceId);
}
DoOnCreate(bundle);
}
This can't be reproduced by following certain steps and is very random. I was wondering if anyone else faces this kind of issue and is there any way to resolve it.
UPDATE: ERROR LOG
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
[MonoDroid] at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <657aa8fea4454dc898a9e5f379c58734>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxChildViewModelCache.Get (System.Int32 index) [0x00000] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxAndroidViewsContainer.TryGetEmbeddedViewModel (Android.Content.Intent intent, MvvmCross.Core.ViewModels.IMvxViewModel& mvxViewModel) [0x0001a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load (Android.Content.Intent intent, MvvmCross.Core.ViewModels.IMvxBundle savedState, System.Type viewModelTypeHint) [0x0005e] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel (MvvmCross.Droid.Views.IMvxAndroidView androidView, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x0006a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxActivityViewExtensions+<>c__DisplayClass1_0.<OnViewCreate>b__1 () [0x0000a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Core.Views.MvxViewExtensionMethods.OnViewCreate (MvvmCross.Core.Views.IMvxView view, System.Func`1[TResult] viewModelLoader) [0x00012] in <c4031697dde6429f89882cbe7dd9e363>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (MvvmCross.Droid.Views.IMvxAndroidView androidView, Android.OS.Bundle bundle) [0x00062] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1[T] eventArgs) [0x0000c] in <c173f0f9274a4c068a91342649d69b4c>:0
[MonoDroid] at (wrapper delegate-invoke) System.EventHandler`1[MvvmCross.Platform.Core.MvxValueEventArgs`1[Android.OS.Bundle]]:invoke_void_object_TEventArgs (object,MvvmCross.Platform.Core.MvxValueEventArgs`1<Android.OS.Bundle>)
[MonoDroid] at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler`1[TEventArgs] eventHandler, System.Object sender, T value) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxDelegateExtensionMethods.cs:21
[MonoDroid] at MvvmCross.Droid.Support.V4.EventSource.MvxEventSourceFragmentActivity.OnCreate (Android.OS.Bundle bundle) [0x00014] in <9170bdccdedc4890abe52ca8a0a43540>:0
[MonoDroid] at The.Droid.Views.Abstract.BaseSupportActivity`1[T].OnCreate (Android.OS.Bundle bundle) [0x00001] in /Users/ali00261/Loyalty-MultiBanner-Mobile/The.Droid/Views/Abstract/BaseSupportActivity.cs:51
[MonoDroid] at The.Droid.Views.HomeView.OnCreate (Android.OS.Bundle bundle) [0x00001] in /Users/ali00261/Loyalty-MultiBanner-Mobile/The.Droid/Views/HomeView.cs:45
[MonoDroid] at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <013f8eacb1954462a2f9d5f677673fee>:0
[MonoDroid] at (wrapper dynamic-method) System.Object:3386debb-3ab9-40f4-9ccb-1b1815452f9b (intptr,intptr,intptr)
[MobileCenterCrashes] Unhandled Exception:
[MobileCenterCrashes] System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
[MobileCenterCrashes] at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x0001e] in <657aa8fea4454dc898a9e5f379c58734>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxChildViewModelCache.Get (System.Int32 index) [0x00000] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxAndroidViewsContainer.TryGetEmbeddedViewModel (Android.Content.Intent intent, MvvmCross.Core.ViewModels.IMvxViewModel& mvxViewModel) [0x0001a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load (Android.Content.Intent intent, MvvmCross.Core.ViewModels.IMvxBundle savedState, System.Type viewModelTypeHint) [0x0005e] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel (MvvmCross.Droid.Views.IMvxAndroidView androidView, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x0006a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxActivityViewExtensions+<>c__DisplayClass1_0.<OnViewCreate>b__1 () [0x0000a] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Core.Views.MvxViewExtensionMethods.OnViewCreate (MvvmCross.Core.Views.IMvxView view, System.Func`1[TResult] viewModelLoader) [0x00012] in <c4031697dde6429f89882cbe7dd9e363>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (MvvmCross.Droid.Views.IMvxAndroidView androidView, Android.OS.Bundle bundle) [0x00062] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1[T] eventArgs) [0x0000c] in <c173f0f9274a4c068a91342649d69b4c>:0
[MobileCenterCrashes] at (wrapper delegate-invoke) System.EventHandler`1[MvvmCross.Platform.Core.MvxValueEventArgs`1[Android.OS.Bundle]]:invoke_void_object_TEventArgs (object,MvvmCross.Platform.Core.MvxValueEventArgs`1<Android.OS.Bundle>)
[MobileCenterCrashes] at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler`1[TEventArgs] eventHandler, System.Object sender, T value) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxDelegateExtensionMethods.cs:21
[MobileCenterCrashes] at MvvmCross.Droid.Support.V4.EventSource.MvxEventSourceFragmentActivity.OnCreate (Android.OS.Bundle bundle) [0x00014] in <9170bdccdedc4890abe52ca8a0a43540>:0
[MobileCenterCrashes] at The.Droid.Views.Abstract.BaseSupportActivity`1[T].OnCreate (Android.OS.Bundle bundle) [0x00001] in /Users/ali00261/Loyalty-MultiBanner-Mobile/The.Droid/Views/Abstract/BaseSupportActivity.cs:51
[MobileCenterCrashes] at The.Droid.Views.HomeView.OnCreate (Android.OS.Bundle bundle) [0x00001] in /Users/ali00261/Loyalty-MultiBanner-Mobile/The.Droid/Views/HomeView.cs:45
[MobileCenterCrashes] at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <013f8eacb1954462a2f9d5f677673fee>:0
[MobileCenterCrashes] at (wrapper dynamic-method) System.Object:3386debb-3ab9-40f4-9ccb-1b1815452f9b (intptr,intptr,intptr)