I am trying to create a mobile application using MVVX. get below error when trying to run the Droid application.
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type ThoughtOfTheDay.ViewModels.LoginViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
Below is the detail of inner exception.
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type ThoughtOfTheDay.ViewModels.LoginViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information ---> MvvmCross.Platform.Exceptions.MvxException: Problem creating viewModel of type LoginViewModel ---> MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to resolve parameter for parameter messenger of type IMvxMessenger when creating ThoughtOfTheDay.ViewModels.LoginViewModel
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00036] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:504
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0002a] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:314
at MvvmCross.Platform.Mvx.IocConstruct (System.Type t) [0x00005] in D:\git\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] in <69bce0378e8e413982d3b552d7e387a8>:0
--- End of inner exception stack trace ---
at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterValues, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00027] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x00015] in <69bce0378e8e413982d3b552d7e387a8>:0
--- End of inner exception stack trace ---
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x00046] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00020] in <69bce0378e8e413982d3b552d7e387a8>:0
at MvvmCross.Droid.Views.MvxAndroidViewsContainer.ViewModelFromRequest (MvvmCross.Core.ViewModels.MvxViewModelRequest viewModelRequest, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00005] in :0
at MvvmCross.Droid.Views.MvxAndroidViewsContainer.CreateViewModelFromIntent (Android.Content.Intent 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] in :0
at MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel (MvvmCross.Droid.Views.IMvxAndroidView androidView, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x0006a] in :0
at MvvmCross.Droid.Views.MvxActivityViewExtensions+<>c__DisplayClass1_0.b__1 () [0x0000a] in :0
at MvvmCross.Core.Views.MvxViewExtensionMethods.OnViewCreate (MvvmCross.Core.Views.IMvxView view, System.Func1[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 delegate-invoke) System.EventHandler1[MvvmCross.Platform.Core.MvxValueEventArgs
1[Android.OS.Bundle]]:invoke_void_object_TEventArgs (object,MvvmCross.Platform.Core.MvxValueEventArgs1<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 bundle) [0x00014] in <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
I am trying to pass IMvxMessenger to the view model. Inner exception message above shows there is a problem resolving IMvxMessenger. Do I need to include something for it in the app.cs\Initialize() ? Let me know if you need more info. Thanks a lot for your time and help.
public LoginViewModel(IMvxMessenger messenger,
IDialogService dialogService,
IUserService userService)
: base(messenger)
{
_userService = userService;
_dialogService = dialogService;
}
Solution: Installed Nuget package for MvvmCross.Plugin.Messenger in the Android project as well. Earlier I had it installed only in the PCL project.