Why does getting a laughable instance created using Moq throw a System.BadImageFormatException?

This question may be related to another question, and this certainly leads to a System.BadImageFormatException. Maybe this is the same thing, but exposed differently?

I have the following code:

public interface IFoo<T> where T : class, new() {
  T FooMethod(object o);
}

public interface IFooRepo {
  F GetFoo<T, F>() where T : class, new() where F : IFoo<T>;
}

Then I have a test that mocks IFooRepo using Moq as follows:

var instance = new Mock<IFooRepo>().Object;

The above code works fine, except when debugging a test with Visual Studio 2008. When I step over the above line, a System.BadImageFormatException is thrown from System.Reflection.Emit via Castle.DynamicProxy. Could it be like something Ayende Rahien sent?

IFooRepo, , ? Is System.Reflection.Emit ? - ?

EDIT: ​​ GetFoo(). ​​ GetFoo < T, F > (), . GDR .

EDIT: , F T BadImageFormatException, . , where F : class, new(), , .

+5
2

FWIW, , , . .

+2

All Articles