我一直在撞击这个人一段时间。
我有一个使用MVVM-Light的WPF项目,当我尝试加载某个视图模型时突然发现错误。
在这个项目中,我有一个viewmodel定位器,它定义了视图模型,如下所示:
ServiceLocator.SetLocatorProvider(Function() SimpleIoc.Default)
''all other dependent services are registered before this view model
SimpleIoc.Default.Register(Of ChangeAddViewModel)()
Public ReadOnly Property ChangeAdd_VM() As ChangeAddViewModel
Get
Return ServiceLocator.Current.GetInstance(Of ChangeAddViewModel)()
End Get
End Property
然后在"父母" view我调用此viewmodel并将其分配给选项卡:
Return _Locator.ChangeAdd_VM
当我尝试返回上面的行时,我收到以下错误:
Message ="调用目标抛出了异常。"
InnerException = {"在缓存中找不到类型: System.ComponentModel.IDataErrorInfo"}
StackTrace ="在System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)" &安培; vbCrLf& "在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object []参数,Object []参数)" &安培; vbCrLf ......
TargetSite = {System.Object InvokeMethod(System.Object, System.Object [],System.Signature,Boolean)}
请注意"在缓存中找不到类型:System.ComponentModel.IDataErrorInfo。"
我使用IDataErrorInfo为视图中的表单字段提供验证。我有超过12个其他视图使用相同的设置,都在工作。
我甚至比较了问题viewModel的构造函数,以确认它的依赖关系全部工作:
Public Sub New(NavService As Navigation.INavigationService,
JobService As IJobDataService,
UserService As IUserService,
EmployeeService As IEmployeeDataService,
ClientService As IClientDataService,
ModelService As IModelService,
ErrorService As IErrorHandling,
dialogService As IDataErrorInfo)
_NavigationService = NavService
_UserService = UserService
_ModelService = ModelService
_errorService = ErrorService
_employeeService = EmployeeService
_clientservice = ClientService
_dialogService = dialogService
项目中还有其他viewModel具有相同的构造函数依赖项,工作正常。此外,所有这些依赖项都是在viewModel注册到viewModelLocator
之前注册的我已经查看了与MVVM-Light相关的缓存问题中未找到的其他类型 我试过了
有人可以帮我弄清楚为什么我的一个视图/ viewModel在创建时会出现错误在缓存中找不到类型:System.ComponentModel.IDataErrorInfo 。
提前致谢
Ĵ
答案 0 :(得分:0)
愚蠢的错误
构造函数中的以下行:
dialogService As IDataErrorInfo
应该是:
dialogService As IDialogService
错误使它变得如此清晰,有时你会对自己的项目视而不见