C# – How to get unit tests to run on a x64 platform

asp.netcnetvisual studio

I have a C# application that must run in x64 mode. The problem is I try to create unit tests that run methods in the x64 application and the unit test project won't even build. I get the following error when it tries to build.

Error loading C:…..\bin\x64\Debug….UnitTests.dll: Unable to load
the test container 'C:…..\bin\x64\Debug….UnitTests.dll' or one
of its dependencies. If you build your test project assembly as a 64
bit assembly, it cannot be loaded. When you build your test project
assembly, select "Any CPU" for the platform. To run your tests in 64
bit mode on a 64 bit processor, you must change your test settings in
the Hosts tab to run your tests in a 32 bit process. Error details:
Could not load file or assembly
'file:///C:…..UnitTests\bin\x64\Debug….UnitTests.dll' or one of
its dependencies. An attempt was made to load a program with an
incorrect format.

I have tried to change the unit test to x64 and also Any CPU and still cannot get it to run. Is there any fix for this?

Best Answer

In VS 2012 and above you can select the default target platform from Test menu under Test Settings|Default Processor Architecture

Visual Studio Test Settings