无法在Visual Studio 2015中运行任何单元测试

时间:2016-09-24 14:42:52

标签: unit-testing visual-studio-2015 .net-framework-version

我最近下载了Visual Studio 2015并将旧项目导入其中。 问题是现在没有单元测试运行,而是我得到了可怕的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)

起初我认为当我将现有项目转移到VS2015时可能出现了问题,但我尝试了一个新创建的项目,同样的事情发生了。我也尝试了MS UnitTestFramework和NUnit。似乎没有任何帮助。

有什么想法吗?

P.S。 - 我还将平台目标设置为x86,并检查我的所有项目都有相同的目标框架。

1 个答案:

答案 0 :(得分:0)

您是否尝试过changing your app config