When attempting to run for the first time on a new machine the unit tests of a project, I got the following error message:
Unable to get type (Test method name), (Test project), Version=126.96.36.199, Culture=neutral, PublicKeyToken=null.
Error: System.BadImageFormatException: Could not load file or assembly (Test project assembly information) or one of its dependencies.
An attempt was made to load a program with an incorrect format.
When attempting to resolve this issue, I came across a few solutions and decided to list what I found in hopes of helping someone else down the road
Changing the Test Settings
Go to Test -> Edit Test Settings -> Local
Then go to Hosts. Make sure Run tests in 64 bit process on 64 bit machine is selected.
Note : The menu options might be different in the different versions of Visual Studio, but should be very similar to the above process.
Standardize the Build Platform
Another solution to try is to set your build platform to the same across the board. Go to your solution, right click, and select properties
Select platform -> Select Any CPU.
Your next best bet is to go into the test project’s properties causing the error and explicitly set this as Any CPU. Even when selecting from above, it doesn’t change the build still.
Don’t Reference a Higher .NET Version
In your solution navigator, click the References project folder, and select the dlls in the project that is throwing the exception. Ensure the .NET versions referenced is either equal to or less then your hosting project.
Between the solutions above, I’ve solved this issue. That’s not to say though there is another solution not listed. If you do happen to find another solution, please leave a comment and I will add as soon as possible. Thanks!