1
votes

I have an exception from Rhino Mocks 3.6.0 and 3.6.1 when mocking the following interface:

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

I can confirm that when removing the Generic "where" association, it will correctly mock.

The Stack trace points firmly at Castle Dynamic Proxy:

System.BadImageFormatException was unhandled by user code HResult=-2147024885 Message=An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Source=mscorlib StackTrace: at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type) 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 interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, 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.<>c__DisplayClass71.<GenerateMock>b__6(MockRepository r) at Rhino.Mocks.MockRepository.CreateMockInReplay[T](Func2 createMock) at Rhino.Mocks.MockRepository.GenerateMock[T](Object[] argumentsForConstructor) at XXXXX.ConfigTestBase.SetUp() in c:\git\MyFork\Workspace\Db.Montage.Common.Tests\Config\ConfigTestBase.cs:line 27 InnerException:

1

1 Answers

1
votes

This is an old bug in old version of DynamicProxy that has been fixed long time ago.

Unfortunately it seems Rhino Mocks still hasn't updated it's dependency on DynamicProxy to a more recent version with this issue fixed.

I think your two options are to build a custom version od Rhino (against new DynamicProxy) or to use another mocking framework that is using more recent version of DynamicProxy (like NSubstitute, FakeItEasy or Moq)