Moq +城堡动态代理 - 异常嘲讽嵌套的通用接口
我收到Castle Dynamic Proxy的一个参数异常,同时使用Moq创建一个模拟对象,该对象正在实现具有接口约束的泛型方法的嵌套通用接口。Moq +城堡动态代理 - 异常嘲讽嵌套的通用接口
异常是:System.ArgumentException:无法将父项设置为接口。
在模拟创建后直接访问模拟的对象属性时发生。 (调用堆栈是在底部为可读性起见)
的代码很简单和自描述:T子句移除:如果其中Z
public interface A<T>
{
void Method<Z>() where Z : T;
}
public interface B
{
}
[Test]
public void MockNestedGenericInterfaceTest()
{
Mock<A<B>> mock = new Mock<A<B>>();
var o = mock.Object; //argument exception here
}
测试不生成异常。
我做了一些调查,发现一张票here。我正在使用最新版本的Moq和Castle。
是否有解决此问题的方法?我看到它工作的唯一方法是手动模拟实现。犀牛嘲笑也不适合我。
谢谢。
调用堆栈:
at System.Reflection.Emit.TypeBuilder.SetParent(Type parent)
在Castle.DynamicProxy.Generators.Emitters.GenericUtil.CopyGenericArguments(MethodInfo的methodToCopyGenericsFrom,字典2 name2GenericType, ApplyGenArgs genericParameterGenerator) at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CopyGenericParametersFromMethod(MethodInfo methodToCopyGenericsFrom) at Castle.DynamicProxy.Generators.InvocationTypeGenerator.Generate(ClassEmitter class, ProxyGenerationOptions options, INamingScope namingScope) at Castle.DynamicProxy.Contributors.InterfaceProxyWithoutTargetContributor.GetInvocationType(MetaMethod method, ClassEmitter emitter, ProxyGenerationOptions options) at Castle.DynamicProxy.Contributors.InterfaceProxyWithoutTargetContributor.GetMethodGenerator(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) at Castle.DynamicProxy.Contributors.CompositeTypeContributor.ImplementMethod(MetaMethod method, ClassEmitter class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod) at Castle.DynamicProxy.Contributors.CompositeTypeContributor.Generate(ClassEmitter class, ProxyGenerationOptions options) at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope) at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) at Moq.Proxy.CastleProxyFactory.CreateProxy(ICallInterceptor interceptor, Type[] interfaces, Object[] arguments) at Moq.Mock
1.b__0() 在Moq.Mock 1.InitializeInstance() at Moq.Mock
1.OnGetObject() 在Moq.Mock`1.get_Object()
此bug已被固定在DynamicProxy的最后一个版本。确保你使用最新版本的起订量为反馈
谢谢,但我们ing Castle.Core.dll ver 2.5.2和Moq.dll ver 4.0.0 - 不起作用。我会在稍后提供一个测试项目来证明这一点。 – Cortlendt
好的。我敢肯定,这个bug是固定的,也许它不是v2.5.2,但是主干虽然...无论如何 - 失败的测试会很棒。 –
好的,我在这里主持了测试项目 - [link](http://ge.tt/8KfdBl6?c)对于我们目前的项目,我们会在一段时间内编译最新的城堡源代码。我会发布它是否会有所帮助。 – Cortlendt