BadImageFormatException when AnyCPU test assembly implements interface from x64 production assembly
I came here searching for the solution for a similar problem. Posting this answer just in case the solution I found helps someone else. This solved it for me in Visual Studio (2012):
Add New Item -> Test Settings Change the testsetting By default this is set to "Force test to run in 32 bit process"
From the menu: Test -> Test Settings -> Select Test Settings File -> Choose the test settings file you have created.
Now run the tests.
Now with Visual Studio 2013 (at least, didn't try in 2012) I didn't have to do anything but choose Test->Test Settings->Default Processor Architecture->x64. Can also use test settings file to achieve the same result. None of those old kluges necessary that you see in other answers and various posting on the web. Since my stuff has to use x64, I added these test cases too just to remind me if I have some setting wrong.
[TestMethod]
public void Running_64Bit_OS()
{
// It was determined to run only in 64 bits.
bool is64BitOS = System.Environment.Is64BitOperatingSystem;
Assert.AreEqual(is64BitOS, true);
}
[TestMethod]
public void Running_64Bit_Process()
{
// We have a requirement that one of the unmanaged DLL is built for 64 bits.
// If you are running MS Test in Visual Studio 2013 and this
// is failing, go to Test->Test Settings->Default Processor Architecture and
// chose x64, then run the tests again. This is not the only method. You
// could also use a test settings file.
bool is64BitProcess = System.Environment.Is64BitProcess;
Assert.AreEqual(is64BitProcess, true);
}
Also, you can go to menu Test->Test Settings->Default Procesor Architecture->X64. It may work.