What are you trying to do, to generate a proxy for a mock object?
On Mon, Sep 21, 2009 at 2:45 PM, Gian Maria Ricci <[email protected]
> wrote:
> Hi to everyone.
>
> I'm facing a little problem with CastleDynamicProxy and Rhino.Mocks. Here
> is how to reproduce It:
>
> Assume that ITest and ITEst2 are two simple interfaces.
>
> This code works
>
> TestInterceptor interceptor = new TestInterceptor() { TestValue = 42 };
>
> ITest t = new AuxClasses.Test();
>
> ITest2 t2 = new Test2();
>
> ProxyGenerator gen = new ProxyGenerator();
>
> gen.CreateInterfaceProxyWithTarget(typeof(ITest), t, interceptor);
>
> gen.CreateInterfaceProxyWithTarget(typeof(ITest2), t2, interceptor);
>
>
>
> I'm creating two concrete classes that implement two interfaces, then I use
> dynamicproxy2 to add an interceptor.
>
> The bug is this one: If the object are mocks it does not works. The
> following code throws an exception.
>
> TestInterceptor interceptor = new TestInterceptor() { TestValue = 42 };
>
> ITest t = MockRepository.GenerateStub<ITest>();
>
> ITest2 t2 = MockRepository.GenerateStub<ITest2>();
>
> ProxyGenerator gen = new ProxyGenerator();
>
> gen.CreateInterfaceProxyWithTarget(typeof(ITest), t, interceptor);
>
> gen.CreateInterfaceProxyWithTarget(typeof(ITest2), t2, interceptor);
>
> IT throws exception in the last line, here is the exception.
>
> System.Reflection.TargetInvocationException : Exception has been thrown by
> the target of an invocation.
>
> ----> System.TypeInitializationException : The type initializer for
> 'Castle.Proxies.ITest2Proxyd4b9bc1d7b074f0e9c21463219ccd322' threw an
> exception.
>
> ----> System.TypeLoadException : Could not load type
> 'ITest2Proxye5fb0daa7f68424da380ca57b9718ffd' from assembly
> 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
> PublicKeyToken=a621a9e7e5c32e69'.
>
> at System.RuntimeFieldHandle.SetValue(Object obj, Object value,
> RuntimeTypeHandle fieldType, FieldAttributes fieldAttr, RuntimeTypeHandle
> declaringType, Boolean& domainInitialized)
>
> at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object
> value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean
> doVisibilityCheck, Boolean doCheckConsistency)
>
> at System.Reflection.RtFieldInfo.SetValue(Object obj, Object value,
> BindingFlags invokeAttr, Binder binder, CultureInfo culture)
>
> at System.Reflection.FieldInfo.SetValue(Object obj, Object value)
>
> at
> Castle.DynamicProxy.Generators.BaseProxyGenerator.InitializeStaticFields(Type
> builtType)
>
> at
> Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateType(String
> typeName, Type proxyTargetType, Type[] interfaces)
>
> at
> Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type
> proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
>
> at
> Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithTarget(Type
> interfaceToProxy, Type[] additionalInterfacesToProxy, Type targetType,
> ProxyGenerationOptions options)
>
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithTarget(Type
> interfaceToProxy, Type[] additionalInterfacesToProxy, Type targetType,
> ProxyGenerationOptions options)
>
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type
> interfaceToProxy, Type[] additionalInterfacesToProxy, Object target,
> ProxyGenerationOptions options, IInterceptor[] interceptors)
>
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type
> interfaceToProxy, Object target, ProxyGenerationOptions options,
> IInterceptor[] interceptors)
>
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type
> interfaceToProxy, Object target, IInterceptor[] interceptors)
>
>
> Alk.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---