问题
I am trying to upgrade an existing Xamarin.Android app from mvvmcross 3.5 to mvvmcross 4.4.0. I have followed this documentation and the app now builds and starts up showing the splashscreen, but it doesn't navigate past the splash screen. When I call ShowViewModel<MainViewModel>()
nothing happens. The last Application output I see is the output below. I have currently no idea where to look next. Anybody have an idea?
mvx:Warning: 17,87 Exception masked ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException (System.ExceptionResource resource) [0x0000b] in <5d9d5f6570654147b240b9398d8953cc>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Insert (TKey key, TValue value, System.Boolean add) [0x0008e] in <5d9d5f6570654147b240b9398d8953cc>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <5d9d5f6570654147b240b9398d8953cc>:0
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0005c] in <1a5e8b31a0e44a97a3b8f85920b2d059>:0
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector) [0x00000] in <1a5e8b31a0e44a97a3b8f85920b2d059>:0
at MvvmCross.Droid.Shared.Presenter.FragmentHostRegistrationSettings.InitializeIfNeeded () [0x00128] in <90641336d9534da69c6ac9e0919ad635>:0
at MvvmCross.Droid.Shared.Presenter.FragmentHostRegistrationSettings.IsTypeRegisteredAsFragment (System.Type viewModelType) [0x00000] in <90641336d9534da69c6ac9e0919ad635>:0
at MvvmCross.Droid.Shared.Presenter.MvxFragmentsPresenter.Show (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x0000c] in <90641336d9534da69c6ac9e0919ad635>:0
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher+<>c__DisplayClass2_0.<ShowViewModel>b__0 () [0x00000] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Droid.Views.MvxAndroidMainThreadDispatcher.RequestMainThreadAction (System.Action action) [0x00019] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher.ShowViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00014] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModelImpl (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle, MvvmCross.Core.ViewModels.MvxRequestedBy requestedBy) [0x0002e] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle, MvvmCross.Core.ViewModels.MvxRequestedBy requestedBy) [0x00000] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel[TViewModel] (MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle, MvvmCross.Core.ViewModels.MvxRequestedBy requestedBy) [0x00000] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Core.ViewModels.MvxAppStart`1[TViewModel].Start (System.Object hint) [0x00013] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Droid.Views.MvxSplashScreenActivity.TriggerFirstNavigate () [0x00005] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Droid.Views.MvxSplashScreenActivity.InitializationComplete () [0x00009] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__7_1 () [0x0000a] in <f6aebf863dc84be7b380cfec8d459508>:0
at MvvmCross.Platform.Core.MvxMainThreadDispatcher.ExceptionMaskedAction (System.Action action) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxMainThreadDispatcher.cs:22
回答1:
The problem was that before upgrading to MvvmCross 4 we had our own implementation of protected override IMvxAndroidViewPresenter CreateViewPresenter ()
in Setup.cs
. After upgrading we changed this implementation to the (standard) implementation:
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
return mvxFragmentsPresenter;
}
The standard implementation didn't work wel with our protected override IList<Assembly> AndroidViewAssemblies
implementation.
Solution:
Removing assemblies.Add (typeof(...).Assembly);
in protected override IList<Assembly> AndroidViewAssemblies { ... }
solved our problem.
来源:https://stackoverflow.com/questions/41801961/mvxwarning-exception-masked-argumentexception-an-item-with-the-same-key-has-a