城堡动态代理的犀牛模拟异常当嘲笑泛型与Where

时间:2013-02-01 19:17:56

标签: mocking rhino-mocks castle-dynamicproxy

在模拟以下界面时,Rhino Mocks 3.6.0和3.6.1有例外:

public interface ic
{
    IComponentConfig<TImpl> Bob<TSvc, TImpl>()
        where TImpl : TSvc;
}

我可以确认在删除Generic“where”关联时,它会正确模拟。

Stack跟踪指向Castle Dynamic Proxy:

  

System.BadImageFormatException未被用户代码处理    的HResult = -2147024885    消息=尝试加载格式不正确的程序。 (HRESULT异常:0x8007000B)    来源= mscorlib程序    堆栈跟踪:         在System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule模块,Int32 tk,ObjectHandleOnStack类型)         在System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()         在System.Reflection.Emit.TypeBuilder.CreateType()         在Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()         在Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()         在Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(类型proxyTargetType,Type []接口,ProxyGenerationOptions选项)         在Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(类型interfaceToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项)         在Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(类型interfaceToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项)         在Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(类型interfaceToProxy,Type [] additionalInterfacesToProxy,ProxyGenerationOptions选项,IInterceptor []拦截器)         在Rhino.Mocks.MockRepository.MockInterface(CreateMockState mockStateFactory,Type type,Type [] extras)         在Rhino.Mocks.MockRepository.CreateMockObject(Type type,CreateMockState factory,Type [] extras,Object [] argumentsForConstructor)         在Rhino.Mocks.MockRepository.DynamicMock [T](Object [] argumentsForConstructor)         在Rhino.Mocks.MockRepository。&lt;&gt; c__DisplayClass7 1.<GenerateMock>b__6(MockRepository r) at Rhino.Mocks.MockRepository.CreateMockInReplay[T](Func 2 createMock)         在Rhino.Mocks.MockRepository.GenerateMock [T](Object [] argumentsForConstructor)         位于c:\ git \ MyFork \ Workspace \ Db.Montage.Common.Tests \ Config \ ConfigTestBase.cs中的XXXXX.ConfigTestBase.SetUp():第27行    InnerException:

1 个答案:

答案 0 :(得分:1)

这是很久以前修复的旧版DynamicProxy中的旧版本。

不幸的是,似乎Rhino Mocks仍然没有将它对DynamicProxy的依赖更新为更新版本并修复了此问题。

我认为您的两个选择是构建自定义版本的Rhino(针对新的DynamicProxy)或使用另一个使用更新版本的DynamicProxy的模拟框架(如NSubstitute,FakeItEasy或Moq)