我正在尝试使用MVVX创建移动应用程序。 尝试运行Droid应用程序时得到以下错误。
MvvmCross.Platform.Exceptions.MvxException:无法从定位器MvxDefaultViewModelLocator为类型ThoughtOfTheDay.ViewModels.LoginViewModel构造和初始化ViewModel - 检查InnerException以获取更多信息
以下是内部异常的详细信息。
MvvmCross.Platform.Exceptions.MvxException:无法从定位器MvxDefaultViewModelLocator构造和初始化类型ThoughtOfTheDay.ViewModels.LoginViewModel的ViewModel - 检查InnerException以获取更多信息---> MvvmCross.Platform.Exceptions.MvxException:创建LoginViewModel类型的viewModel时出现问题---> MvvmCross.Platform.Exceptions.MvxIoCResolveException:创建ThoughtOfTheDay.ViewModels.LoginViewModel 时无法解析IMvxMessenger类型的参数信使的参数
在MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues(System.Type类型,System.Reflection.ConstructorInfo firstConstructor)[0x00036]在D:\ git \ MvvmCross \ MvvmCross \ Platform \ Platform \ IoC \ MvxSimpleIoCContainer.cs:504
在MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type类型)[0x0002a]在D:\ git \ MvvmCross \ MvvmCross \ Platform \ Platform \ IoC \ MvxSimpleIoCContainer.cs:314
在D:\ git \ MvvmCross \ MvvmCross \ Platform \ Platform \ Mvx.cs中的MvvmCross.Platform.Mvx.IocConstruct(System.Type t)[0x00005]:170
在MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load(System.Type viewModelType,MvvmCross.Core.ViewModels.IMvxBundle parameterValues,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00000] in< 69bce0378e8e413982d3b552d7e387a8>:0
---内部异常堆栈跟踪结束---
在MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load(System.Type viewModelType,MvvmCross.Core.ViewModels.IMvxBundle parameterValues,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00027] in< 69bce0378e8e413982d3b552d7e387a8>:0
在MvvmCross.Core.ViewModels.MvxViewModelLoader.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] in< 69bce0378e8e413982d3b552d7e387a8>:0
在MvvmCross.Droid.Views.MvxAndroidViewsContainer.ViewModelFromRequest(MvvmCross.Core.ViewModels.MvxViewModelRequest viewModelRequest,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00005] in:0
在MvvmCross.Droid.Views.MvxAndroidViewsContainer.CreateViewModelFromIntent(Android.Content.Intent intent,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x00027] in:0
在MvvmCross.Droid.Views.MvxAndroidViewsContainer.Load(Android.Content.Intent intent,MvvmCross.Core.ViewModels.IMvxBundle savedState,System.Type viewModelTypeHint)[0x00089] in:0
在MvvmCross.Droid.Views.MvxActivityViewExtensions.LoadViewModel(MvvmCross.Droid.Views.IMvxAndroidView androidView,MvvmCross.Core.ViewModels.IMvxBundle savedState)[0x0006a] in:0
在MvvmCross.Droid.Views.MvxActivityViewExtensions +<> c__DisplayClass1_0.b__1()[0x0000a] in:0
在MvvmCross.Core.Views.MvxViewExtensionMethods.OnViewCreate(MvvmCross.Core.Views.IMvxView视图,System.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 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>)
at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler
1 [TEventArgs] eventHandler,System.Object发送者,T值)[0x00000]在D:\ git \ MvvmCross \ MvvmCross \ Platform \ Platform \ Core \ MvxDelegateExtensionMethods.cs:21
在MvvmCross.Platform.Droid.Views.MvxEventSourceActivity.OnCreate(Android.OS.Bundle bundle)[0x00014] in&lt; 4230cf00b647458f9b3e211590e6cc9d&gt;:0
at ThoughtOfTheDay.Droid.Views.LoginView.OnCreate(Android.OS.Bundle bundle)[0x00002]在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项目中MvvmCross.Plugin.Messenger的Nuget包。 之前我只在PCL项目中安装了它。
答案 0 :(得分:4)
解决方案:安装了Android项目中MvvmCross.Plugin.Messenger的Nuget包。之前我只在PCL项目中安装了它。
答案 1 :(得分:0)
听起来你错过了插件的引导程序。
确保使用以下内容在Bootstrap文件夹中创建一个类:
using MvvmCross.Platform.Plugins;
namespace your.name.space.Bootstrap
{
public class MessengerPluginBootstrap
: MvxPluginBootstrapAction<MvvmCross.Plugins.Messenger.PluginLoader>
{
}
}
这将使用IoC容器注册插件。
或者,您可以在InitializeLastChance
文件的Setup.cs
中自行注册:
Mvx.RegisterSingleton<IMvxMessenger>(() => new MvxMessengerHub());