Wpf 为什么MVVMLite返回一个";“在缓存中找不到类型”;错误?
我对我使用的界面进行了更改。我在该接口的ViewModelLocator中实例化了一个对象。我有一个单元测试来测试它。单元测试以前工作得很好,现在不行了。以下是接口的旧定义:Wpf 为什么MVVMLite返回一个";“在缓存中找不到类型”;错误?,wpf,mvvm-light,Wpf,Mvvm Light,我对我使用的界面进行了更改。我在该接口的ViewModelLocator中实例化了一个对象。我有一个单元测试来测试它。单元测试以前工作得很好,现在不行了。以下是接口的旧定义: public interface IViewService { bool ShowMessage(string title, string message); } 下面是我如何改变它的: public interface IViewService { System.Windows.MessageBoxRe
public interface IViewService
{
bool ShowMessage(string title, string message);
}
下面是我如何改变它的:
public interface IViewService
{
System.Windows.MessageBoxResult ShowMessage(string Title, string Message, DialogButtonsEnum ButtonsToShow);
}
(DialogButtonsEnum是我创建的枚举。)
下面是ViewModelLocator类中出现问题的行:
static public IViewService ViewService
{
get
{
return ServiceLocator.Current.GetInstance<IViewService>();
}
}
static public IViewService ViewService
{
得到
{
返回ServiceLocator.Current.GetInstance();
}
}
它在GetInstance()调用时出错,引发以下错误:
HResult=-2146233088
Message=在缓存中找不到类型:LRAT.CoreServices.IViewService。
Source=GalaSoft.MvvmLight.Extras
那么,我做错了什么?如何修复此问题?在哪里注册接口的实现?如果尝试执行
ServiceLocator.Current.GetInstance(),通常会引发此异常代码>而没有调用ServiceLocator.Current.Register()
。您忘了注册实现了吗?您可能想重新表述您的标题,它现在说的与您的问题相反:)