3.5 Bug: Test method threw exception: System.BadImageFormatException

75 views
Skip to first unread message

GMan6

unread,
Jun 27, 2008, 1:09:12 PM6/27/08
to Rhino.Mocks
With the new 3.5 libraries, I once again get this error when creating
a strict or dynamic mock but NOT remoting mock of an interface with a
method that constrains a generic type to another generic type like
this:

Interface method causing the mock issue:
void DoSomethingToCollection<TCollection, TMyModel>(TCollection
myCollection) where TCollection : ICollection<TMyModel>;

Error:
Test method StrictMockGenericConstraintTest.SampleTest.TestMethod1
threw exception: System.BadImageFormatException: An attempt was made
to load a program with an incorrect format. (Exception from HRESULT:
0x8007000B).

Here is a full sample, I wrapped the static GenerateMock methods on
the repository and added a strict and remoting version based on the
source for comparrison between the mock types. Again this is just an
example, uncomment the remoting mock call and you will see it work.
This was a bug that I believe was fixed in 3.4 that seems to have
crept back in...


using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace StrictMockGenericConstraintTest
{
[TestClass]
public class SampleTest:TestBase
{
[TestMethod]
public void TestMethod1()
{
//This fails
var mockBar = GenerateStrictMock<IBar>();
//This fails
//var mockBar = GenerateDynamicMock<IBar>();
//This would work
//var mockBar = GenerateStrictMockWithRemoting<IBar>();

var foo = new Foo(mockBar);
}
}

public class Foo{
public Foo(IBar bar){ }
public void MethodUnderTest(){ }
}

public interface IBar{
void DoSomethingToCollection<TCollection,
TMyModel>(TCollection myCollection) where TCollection :
ICollection<TMyModel>;
}


public abstract class TestBase
{
public static T GenerateDynamicMock<T>()
{
var mock = MockRepository.GenerateMock<T>();
return mock;
}

public static T GenerateStrictMock<T>()
{
MockRepository repository = new MockRepository();
T mock = repository.StrictMock<T>();
repository.Replay(mock);
return mock;
}

public static T GenerateStrictMockWithRemoting<T>()
{
MockRepository repository = new MockRepository();
T mock = repository.StrictMockWithRemoting<T>();
repository.Replay(mock);
return mock;
}
}
}

Ayende Rahien

unread,
Jun 27, 2008, 3:25:21 PM6/27/08
to Rhino...@googlegroups.com
Known bug with the CLR, I am afraid.
Reply all
Reply to author
Forward
0 new messages