我想創建一個使用MVVX的移動應用程序。 嘗試運行Droid應用程序時出現以下錯誤。MVVX無法初始化從MvxDefaultViewModelLocator ViewModel
MvvmCross.Platform.Exceptions.MvxException:無法構造和從定位器MvxDefaultViewModelLocator初始化視圖模型爲型ThoughtOfTheDay.ViewModels.LoginViewModel - 檢查的InnerException以獲取更多信息
下面是內部異常的細節。 MvvmCross.Platform.Exceptions.MvxException:未能從定位器MvxDefaultViewModelLocator爲類型ThoughtOfTheDay.ViewModels.LoginViewModel構造並初始化ViewModel - 檢查InnerException以獲取更多信息---> MvvmCross.Platform.Exceptions.MvxException:創建類型爲LoginViewModel的viewModel的問題---> MvvmCross.Platform.Exceptions.MvxIoCResolveException:創建失敗在MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues ThoughtOfTheDay.ViewModels.LoginViewModel (System.Type的類型,系統時解析類型IMvxMessenger的參數信使參數。在MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type)中的D:\ git \ MvvmCross \ MvvmCross \ Platform \ Platform \ IoC \ MvxSimpleIoCContainer.cs:504 中的Reflection.ConstructorInfo firstConstructor)[0x00036]在D:\ git \ MvvmCross \ Platform \ Platform \ IoC \ MvxSimpleIoCContainer.cs中輸入[0x0002a] MvvmCross \ MvvmCross \ Platform \ Platform \ Mvx.cs:170 at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load(System.Type viewModelType,MvvmCross.Core.ViewModels.IMvxBundle parameterValues,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00000 ]在< 69bce0378e8e413982d3b552d7e387a8>:0 ---在MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load(System.Type的viewModelType,MvvmCross.Core.ViewModels.IMvxBundle的parameterValues,MvvmCross.Core內部異常堆棧跟蹤--- 結束。 ViewModels.IMvxBundle savedState)[0x00027] < 69bce0378e8e413982d3b552d7e387a8>:0 at MvvmCross.Core.ViewModels.MvxViewModel Loader.LoadViewModel(MvvmCross.Core.ViewModels.MvxViewModelRequest請求,MvvmCross.Core.ViewModels.IMvxBundle savedState,MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator)[0x00015]在< 69bce0378e8e413982d3b552d7e387a8>:0 ---完內部異常堆棧跟蹤的---在 MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel(MvvmCross.Core.ViewModels.MvxViewModelRequest請求,MvvmCross.Core.ViewModels.IMvxBundle savedState,MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator)[0x00046]在< 69bce0378e8e413982d3b552d7e387a8>: 0 在MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel(MvvmCross.Core.ViewModels.MvxViewModelRequest請求,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00020]在< 69bce0378e8e413982d3b552d7e387a8>:0 在MvvmCross.D roid.Views.MvxAndroidViewsContainer.ViewModelFromRequest(MvvmCross.Core.ViewModels.MvxViewModelRequest viewModelRequest,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00005]在:0 在MvvmCross.Droid.Views.MvxAndroidViewsContainer.CreateViewModelFromIntent(Android.Content.Intent意圖,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00027] in:0 at MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load(Android.Content.Intent intent,MvvmCross.Core.ViewModels.IMvxBundle savedState,System.Type viewModelTypeHint)[ 0x00089]在:0 在MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel(MvvmCross.Droid.Views.IMvxAndroidView androidView,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x0006a]在:0 在MvvmCross.Droid.Views.MvxActivityViewExtensions + <> c__DisplayClass1_0.b__1()[0x0000a] in:0 在MvvmCross.Core.Views.MvxViewExtensionMethods.OnViewCreate(MvvmCross.Core.Views.IMvxView視圖,系統。Func 1[TResult] viewModelLoader) [0x00012] in <69bce0378e8e413982d3b552d7e387a8>:0 at MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (MvvmCross.Droid.Views.IMvxAndroidView androidView, Android.OS.Bundle bundle) [0x00062] in <f6aebf863dc84be7b380cfec8d459508>:0 at MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs
1 [T] eventArgs)[0x0000c] in:0 at(wrapper委託調用)System.EventHandler 1[MvvmCross.Platform.Core.MvxValueEventArgs
1 [Android.OS.Bundle]]:invoke_void_object_TEventArgs(object,MvvmCross.Platform.Core.MvxValueEventArgs 1<Android.OS.Bundle>) 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 at MvvmCross.Platform.Droid.Views.MvxEventSourceActivity.OnCreate( Android.OS.Bundle包)[0x00014] < 4230cf00b647458f9b3e211590e6cc9d>:0 at ThoughtOfTheDay.Droid.Views.LoginView.OnCreate(Android.OS.Bundle bundle)[0x00002] in C:\ Work \ MobileDev \ ThoughtOfTheDay \ ThoughtOfTheDay \ ThoughtOfTheDay.Droid \ Views \ LoginView.cs:15
我正在嘗試將IMvxMessenger傳遞給視圖模型。上面的內部異常消息顯示解決IMvxMessenger問題。我是否需要在app.cs \ Initialize()中包含一些內容?讓我知道你是否需要更多信息。非常感謝您的時間和幫助。
public LoginViewModel(IMvxMessenger messenger,
IDialogService dialogService,
IUserService userService)
: base(messenger)
{
_userService = userService;
_dialogService = dialogService;
}
解決方法:安裝在Android項目的NuGet包MvvmCross.Plugin.Messenger爲好。 早些時候,我只將它安裝在PCL項目中。
感謝Cheesebaron,我已經這樣做了,在我的情況下,解決方案在上面列出了我的問題。 –
啊對了。沒有看到。在特定於平臺的項目中安裝插件的目的是實際創建該引導文件,但也允許在該平臺上使用該插件。無論如何,大多數插件都要求您將其安裝在特定於平臺的項目中。無論哪種方式。添加你自己的答案,並接受它:) – Cheesebaron
感謝您的信息隊友:) –