Question

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?

Was it helpful?

Solution

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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top