模拟帮助?我找不到问题所在
我有一个这样定义的接口:
public interface IDatabase{ void Get<TTypeToFetch> ();}
当我尝试这样做时: Mockery 嘲讽 = new Mockery(); IDatabase db = mockery.NewMock
我收到以下错误:
System.TypeLoadException:System.TypeLoadException:方法实现中的主体签名和声明不匹配
了什么问题? (我使用 Visual Studio 2008 和 nmock2) 请大家给我一个答案,我必须尽快完成这个工作。 谢谢, 路易莎
I have an interface definded like this:
public interface IDatabase{ void Get<TTypeToFetch> ();}
and when I try to do:Mockery mockery = new Mockery();
IDatabase db = mockery.NewMock<IDatabase>();
I get the following error:
System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match
What is wrong? (I am using Visual Studio 2008 with nmock2)
Please could everyone give me an answer, I have to finish this soon.
Thanks,
Luisa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这可能是 NMock 的问题,甚至可能是一个错误。类型
IDatabase
不是通用的,因此当您调用Get
时,可以在运行时使用不同的T
。但是当 NMock 生成模拟时,它似乎并不理解这种情况,并且 kablammo ——每个方法签名都是不同的,具体取决于提供的类型参数。尝试这样做:
另外,
Get
的类型不应该是T
,而不是void
吗?I think this may be a problem with NMock, possibly even a bug. The type
IDatabase
is not generic, so when you invokeGet<T>
, differentT
s could be used at runtime. But when NMock is generating the mock, it doesn't appear to understand that this is the case, and kablammo -- each method signature is different, depending on the type parameter supplied.Try doing this instead:
Also, shouldn't the type of
Get
beT
, notvoid
?我自己的界面也有同样的例外。当我将界面更改为公共时,一切运行正常。
I had the same exception with my own interface. When i change interface to be public everything runs ok.