使用.Net 3.5测试项目进行单元测试与VS 2012不兼容

5
我有一个Visual Studio 2012,其中有两个项目(简单点说):

  • MyProject(类库)
  • MyProject.Test(MS Test项目)

因为我必须针对.Net 3.5,我重新定位测试项目的框架

然而,在这一点上,单元测试停止工作了(如果我离开4.5,它就可以正常工作)。

具体来说,QTAgent.exe崩溃:

[Window Title]
QTAgent.exe

[Main Instruction]
QTAgent.exe has stopped working

[Content]
A problem caused the program to stop working correctly. Please close the program.

[Close the program] [Debug the program]

在Visual Studio的输出窗口中,我可以看到:
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.clr20.exe', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.Core.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\SMDiagnostics\3.0.0.0__b77a5c561934e089\SMDiagnostics.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.ServiceModelSink\3.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.ServiceModelSink.dll', Symbols loaded.
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Microsoft.VisualStudio.TestPlatform.Utilities.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Diagnostics.Measurement\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Diagnostics.Measurement.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.dll', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.TmiAdapter.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.TeamSystem.Licensing.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Common\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Common.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 11.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\Extensions\Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.UnitTestFramework\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.ExecutionCommon\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Resource\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Resource.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.TMI\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.TMI.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Tip\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Tip.dll', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'Microsoft.VisualStudio.TestTools.Exceptions.EqtDataException' occurred in Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel.dll
A first chance exception of type 'Microsoft.VisualStudio.TestTools.Exceptions.EqtDataException' occurred in Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel.dll
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.AssemblyResolver\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.AssemblyResolver.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Projects\_Shared\MyCorp.Shared\Src\MyCorp.MyProject\MyCorp.MyProject.Test\bin\Debug\MyCorp.MyProject.Test.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.QualityTools.Controller.SpooledJob.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.ControllerObject\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.ControllerObject.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.AgentProcessManager\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.AgentProcessManager.dll', Symbols loaded.
'vstest.executionengine.clr20.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Runtime.Remoting\2.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\QTAgent_35.exe', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.ExecutionCommon\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Common\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Common.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Resource\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Resource.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.AgentObject\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.AgentObject.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Runtime.Remoting\2.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.AgentProcessManager\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.AgentProcessManager.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.UnitTestFramework\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.AssemblyResolver\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.AssemblyResolver.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.TeamSystem.Licensing.dll', Symbols loaded.
'QTAgent_35.exe' (Managed (v2.0.50727)): Loaded 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Enterprise.AspNetHelper.dll', Symbols loaded.
The program '[7756] QTAgent_35.exe: Managed (v2.0.50727)' has exited with code -1073740940 (0xc0000374).
The thread 'TestAgentProcessMonitor' (0x1854) has exited with code 0 (0x0).
The thread 'Local run message listener test message receiver cleanup thread' (0x2110) has exited with code 0 (0x0).
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualStudio.QualityTools.ControllerObject.dll
The thread 'Controller: Release worker thread for agent SP2010' (0x18ac) has exited with code 0 (0x0).
A first chance exception of type 'System.Threading.ThreadInterruptedException' occurred in Microsoft.VisualStudio.QualityTools.ControllerObject.dll
The thread 'Controller: heartbeat thread' (0x1db0) has exited with code 0 (0x0).
The thread 'Controller: state execution thread for run d7a5f846-868c-486b-ae22-40d27396a225' (0x1e1c) has exited with code 0 (0x0).
The thread 'Controller: run queue thread' (0x23ec) has exited with code 0 (0x0).
The thread 'Controller: deployment queue thread' (0x25ec) has exited with code 0 (0x0).
The thread '<No Name>' (0x128c) has exited with code 0 (0x0).
The thread '<No Name>' (0x2028) has exited with code 0 (0x0).
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll
A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.ServiceModel.dll
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll
A first chance exception of type 'System.ServiceModel.CommunicationObjectAbortedException' occurred in System.ServiceModel.dll
The program '[6200] vstest.executionengine.clr20.exe: Managed (v2.0.50727)' has exited with code 0 (0x0).

如果我将调试器附加到QTAgent.exe进程上,我可以看到这个堆栈跟踪: Stacktrace 有人知道为什么我的设置不起作用以及如何解决吗?
背景介绍一下,我正在创建SharePoint 2010单元测试,因此我设置了测试项目以针对.NET 3.5(SharePoint与CLR 4不兼容)。
我还设置了测试项目在64位主机上运行。

1
BadImageFormatException是致命的。通常是由于尝试在64位测试运行程序中加载只能在32位模式下工作的程序集引起的。或者反过来。或者是由于加载了.NET 4程序集引起的。 - Hans Passant
谢谢@HansPassant,我已经成功运行了我的测试(请参见我的答案)。但是我并不满意,因为我不明白根本原因是什么。也许你知道一个可以帮助识别程序集加载问题的工具? - Steve B
1
Fuslogvw.exe。简单的解释是您运行了错误位数的测试运行器。 - Hans Passant
谢谢,我会调查一下。只是有点惊讶这个不能直接使用。 - Steve B
2个回答

8

我其实不知道为什么,但是当我删除了 mysolution.v11.suo 文件后,测试开始正常工作了。

实际上,区别在于我不再有测试设置文件 (.testsettings)。

我不得不删除suo文件,因为VS 2012不允许取消选择测试设置文件。

我还必须强制使用X64模式(我的托管应用程序SharePoint的要求),但这次,我没有在测试设置文件中设置模式,而是使用了 TEST->TEST SETTINGS->DEFAULT PROCESSOR ARCHITECTURE-> X64


删除 .suo 文件和 .testsettings 文件并重新启动 VS 可以解决问题。 - Bartosz Węgielewski

0

我不知道你的环境是怎样的,但在我的环境中,只有当输出文件夹不在项目文件夹上面时才能正常工作。我的意思是说,".. \ Debug" 不起作用,但 "bin \ Debug" 可以正常工作。

错误信息与你收到的差不多。(至少在我的环境中是这样的。)


你是在说普通项目还是测试项目?但两者都设置为 Bin\debug :'( - Steve B

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接