Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 为什么MVVMLite返回一个";“在缓存中找不到类型”;错误?_Wpf_Mvvm Light - Fatal编程技术网

Wpf 为什么MVVMLite返回一个";“在缓存中找不到类型”;错误?

Wpf 为什么MVVMLite返回一个";“在缓存中找不到类型”;错误?,wpf,mvvm-light,Wpf,Mvvm Light,我对我使用的界面进行了更改。我在该接口的ViewModelLocator中实例化了一个对象。我有一个单元测试来测试它。单元测试以前工作得很好,现在不行了。以下是接口的旧定义: public interface IViewService { bool ShowMessage(string title, string message); } 下面是我如何改变它的: public interface IViewService { System.Windows.MessageBoxRe

我对我使用的界面进行了更改。我在该接口的ViewModelLocator中实例化了一个对象。我有一个单元测试来测试它。单元测试以前工作得很好,现在不行了。以下是接口的旧定义:

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()
。您忘了注册实现了吗?您可能想重新表述您的标题,它现在说的与您的问题相反:)