当前类型是接口,无法构造.您是否缺少类型映射? [英] The current type is an interface and cannot be constructed. Are you missing a type mapping?

查看:551
本文介绍了当前类型是接口,无法构造.您是否缺少类型映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器类,该类负责双击命令,并依次调用一种向用户弹出窗口的方法.像这样的东西:

I have a controller class that takes care for the double click command and in turn calls a method that popups a window to the user. Something like :

var popup = container.GetService<PopupCommand>();

在上面的行中,它抛出一个错误,说: 当前类型PopupCommand.IPopupDataHandler是接口,无法构造.您是否缺少类型映射?

In the above line it throws an error saying : The current type, PopupCommand.IPopupDataHandler, is an interface and cannot be constructed. Are you missing a type mapping?

我更新了包含用于container.GetService()的方法的DLL,然后才能正常工作.

I updated the DLL that contained a method for container.GetService(), before that it used to work fine.

我尝试在Google中进行搜索,但是类似的问题与Unity有关,并且我怀疑我的问题是否与Unity有关.

I tried searching in google, but the issues similar are more related to Unity, and i doubt whether my issue is anywhere related to Unity.

推荐答案

基本上,编译器会告诉您您正在尝试实例化接口.

Basically the compiler tells you that you are trying to instantiate an interface.

container.GetService<PopupCommand>()可能会带您回到名为PopupCommand.IPopupDataHandler的接口,您可能需要将其强制转换为所需的类型或将类型更改为对象,还应该检查方法的约束-它可能会丢失new约束.

container.GetService<PopupCommand>() probably brings you back an interface named PopupCommand.IPopupDataHandler, you probably need to cast it to the type you need or change the type to an object, you should also check the constrains of the method - it could be missing the new constraint.

这篇关于当前类型是接口,无法构造.您是否缺少类型映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆