【发布时间】:2010-10-26 19:29:24
【问题描述】:
这个问题可能与another 问题有关,它肯定会导致 System.BadImageFormatException。也许是一样的东西,但暴露的不同?
我有以下代码:
public interface IFoo<T> where T : class, new() {
T FooMethod(object o);
}
public interface IFooRepo {
F GetFoo<T, F>() where T : class, new() where F : IFoo<T>;
}
然后我有一个使用 Moq 模拟 IFooRepo 的测试,如下所示:
var instance = new Mock<IFooRepo>().Object;
除了使用 Visual Studio 2008 调试测试时,上述代码运行良好。当我越过上述行时,System.BadImageFormatException 通过 Castle.DynamicProxy 从 System.Reflection.Emit 引发。这可能类似于something Ayende Rahien 发布的内容吗?
现在的解决方法是为 IFooRepo 实现一个假的,但我很好奇为什么会为这种场景生成一个坏图像并且有解决办法吗? System.Reflection.Emit 有问题吗?还是我在自己的代码中遗漏了一些明显的东西?
编辑:为 GetFoo() 发布了不正确的签名。将签名更正为 GetFoo
编辑:似乎如果对 F 的约束包括类型参数 T BadImageFormatException 就会引发。但我将其更改为 where F : class, new(),然后一切正常。
【问题讨论】:
标签: debugging moq reflection.emit castle-dynamicproxy