Search code examples
unit-testingvisual-studio-2015.net-framework-version

Cannot run any unit tests in Visual Studio 2015


I have recently downloaded Visual Studio 2015 and imported an old project into it. The problem is that now none of the unit tests run, and instead I get the dreaded BadImageFormatException

Unable to get type GameTests.UnitTest1. Error: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\...\bin\Debug\GameTests.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'file:///C:\Users\...\bin\Debug\GameTests.dll'
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.VisualStudio.TestPlatform.MSTestFramework.TypeCache.LoadType(String typeName, String assemblyName)

At first I thought that there might have been something wrong when I transferred an existing project to VS2015, but I have tried with a newly created project, and the same happens. I have also tried both MS UnitTestFramework and NUnit. Nothing seems to help.

Any ideas?

P.S. - I've also set the Platform target to x86 and checked that all my projects have the same target framework.


Solution

  • Did you try changing your app config?