views:

554

answers:

3

This may or may not be a multi-interface problem, but I'm doing something like this:

var mockInterface1 = new Mock<IInterface1>();
var mockInterface2 = mockInterface1.As<IInterface2>();
mockInterface1.Expect( foo => foo.Foo(It.IsAny<IInterface3>() ) );

...

otherObject.DoSomething( (IInterface1)mockInterface2.Object );

On the DoSomething line at runtime I get:

MyTest (TestFixtureSetUp): System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.

----> System.TypeInitializationException : The type initializer for 'IInterface1Proxy184f83d417624e05b450fa40c2c5d35c' threw an exception.

----> System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Does this have something to do with my not having the right Expect code, or is it related to the multiple interfaces in my mock, or something else?

A: 

I know this isn't an answer as such, but it does sound like a bug in MOQ. What version are you using? I just tried your example with 2.6 (2.6.1014.1) and I don't get an exception.

Steve Dunn
I'm using 2.6 (don't know the exact version, but libs say 2.6)
dviljoen
Just checked again: 2.6.1014.1
dviljoen
+3  A: 

I found this link: Castle Project Topic

which seems to indicate that its a problem in Castle's DynamicProxy, which is used by Moq (and RhinoMocks).

dviljoen
I get this as well when using Moq 3.0.308.2.
Jonathon Watney
A: 

This works as of Moq 3.1.416.3

Ryan Cromwell