我正在尝试将现有的Xamarin.Android应用程序从mvvmcross 3.5升级到mvvmcross 4.4.0。我已关注this documentation,现在应用程序已构建并启动显示启动画面,但它并未通过启动画面。当我打电话给ShowViewModel<MainViewModel>()
时,没有任何反应。我看到的最后一个Application输出是下面的输出。我目前不知道下一步该在哪里。有人有想法吗?
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
答案 0 :(得分:2)
问题是在升级到MvvmCross 4之前,我们在protected override IMvxAndroidViewPresenter CreateViewPresenter ()
中实现了Setup.cs
。升级后,我们将此实现更改为(标准)实现:
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
return mvxFragmentsPresenter;
}
标准实施与我们的protected override IList<Assembly> AndroidViewAssemblies
实施并不相符。
<强>解决方案:强>
删除assemblies.Add (typeof(...).Assembly);
中的protected override IList<Assembly> AndroidViewAssemblies { ... }
解决了我们的问题。