Sounds like you're running into this issue:

http://groups.google.com/group/rhinomocks/browse_thread/thread/2c1b53bf66b77b8e?tvc=2&q=Dynamic+mock+of+a+generics+interface+that+uses+a+generic+constraint

The recommended fix (according to the thread) is to build your own
copy of Rhino.Mocks with the latest DynamicProxy (which has this bug
fixed).

---
Patrick Steele
http://weblogs.asp.net/psteele



On Wed, Jun 23, 2010 at 8:05 AM, Jens Melgaard <[email protected]> wrote:
> Hello there, we have an issue Mocking out a few of our interfaces, for
> now it ain't a huge problem for us since we have a workaround that is
> tolerable for the moment.
>
> Here is the Full StackTrace:
>
> System.BadImageFormatException: An attempt was made to load a program
> with an incorrect format. (Exception from HRESULT: 0x8007000B)
> at System.Reflection.Emit.TypeBuilder._TermCreateClass(Int32 handle,
> Module module)
> at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
> at System.Reflection.Emit.TypeBuilder.CreateType()
> at
> Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
> at
> Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
> at
> Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type
> proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
> at
> Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type
> theInterface, Type[] interfaces, ProxyGenerationOptions options)
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(Type
> theInterface, Type[] interfaces, ProxyGenerationOptions options)
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type
> theInterface, Type[] interfaces, ProxyGenerationOptions options,
> IInterceptor[] interceptors)
> at
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type
> theInterface, Type[] interfaces, IInterceptor[] interceptors)
> at Rhino.Mocks.MockRepository.MockInterface(CreateMockState
> mockStateFactory, Type type, Type[] extras)
> at Rhino.Mocks.MockRepository.CreateMockObject(Type type,
> CreateMockState factory, Type[] extras, Object[]
> argumentsForConstructor)
> at Rhino.Mocks.MockRepository.DynamicMock<T>(Object[]
> argumentsForConstructor)
> at Rhino.Mocks.MockRepository.GenerateMock<T>(Object[]
> argumentsForConstructor)
> at
> Systematic.OMSIS.Runtime.Presentation.Services.Test.TransactionServiceAgentTest.SetUp()
> in TransactionServiceAgentTest.cs: line 23
>
> The problem is rather simple to "solve" for us since we "own" the
> interface.
> Here is the interface:
>
>    public interface IServiceClientFactory
>    {
>        TService Create<TService, TClient>() where TClient:TService;
>    }
>
> If we make the following very small change to the interface, the error
> disappears.
>
>    public interface IServiceClientFactory
>    {
>        TService Create<TService, TClient>();
>    }
>
> As might be noted, it is the the constraints on the Type Parameters
> that is gone.
> And now it works!...
>
> We are a bit unsure if it is Rhino.Mocks or Castle.DynamicProxy that
> contains the actual problem, since Castle may have extra demands on
> generating a proxy in the specific context above... or it may be
> castle that just has the issue...
>
> Anyways since we found a rather specific little detail we thought it
> could help to post it here, you can figure out if it should be
> forwarded i hope...
>
> Kind Regards
> Jens Melgaard
> Systematic

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" 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/rhinomocks?hl=en.

Reply via email to