【问题标题】:Type load exception during discovering MSTest Framework tests发现 MSTest 框架测试期间的类型加载异常
【发布时间】:2019-01-30 22:14:37
【问题描述】:

最近,当我们尝试使用 Jenkins 的 MSTest 运行测试时,我们收到了“TargetInvocationException”错误。今天我从 MSTest 切换到 VsTest.Console.exe,虽然我能够得到更详细的错误消息,但问题是一样的。

我在 Google 上找不到任何可能导致此异常的迹象。如果我理解正确,那么异常不是来自我们的测试,而是来自 MSTest 框架。

TpTrace Warning: 0 : 10032, 3, 2018/10/31, 15:22:23.137, 54721019933, testhost.x86.exe, TestSettings will soon be deprecated for automated unit and functional testing scenarios. It is recommended that you use RunSettings. To learn more, see http://aka.ms/runsettings
    TpTrace Verbose: 0 : 10032, 3, 2018/10/31, 15:22:23.137, 54721020301, testhost.x86.exe, TestRequestHandler.SendData:  sending data from testhost: {"Version":2,"MessageType":"TestSession.Message","Payload":{"MessageLevel":1,"Message":"TestSettings will soon be deprecated for automated unit and functional testing scenarios. It is recommended that you use RunSettings. To learn more, see http://aka.ms/runsettings"}}
    TpTrace Error: 0 : 10032, 3, 2018/10/31, 15:22:23.256, 54721419216, testhost.x86.exe, TmiDiscoveryRequest: Error occured while discovering tests from source F:\Jenkins\Workspace\[...]\My.dll. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExtensionInfo' threw an exception. ---> System.TypeLoadException: Could not load type 'Microsoft.VisualStudio.TestTools.Common.TestTypesXml' from assembly 'Microsoft.VisualStudio.QualityTools.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
       at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExtensionInfo..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExtensionInfo.GetExtensionNames(IWarningHandler warningHandler)
       at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestTip.InitializeExtensions()
       at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestTip..ctor(ITmi tmiInstance)
       --- End of inner exception stack trace ---
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Activator.CreateInstance(Type type, Object[] args)
       at Microsoft.VisualStudio.TestTools.TestManagement.TipDelayLoader.LoadTip()
       at Microsoft.VisualStudio.TestTools.TestManagement.TipDelayLoader.GetTip()
       at Microsoft.VisualStudio.TestTools.TestManagement.Tmi.GetTipsFromTestTypeInfos(IList`1 infos)
       at Microsoft.VisualStudio.TestTools.TestManagement.Tmi.LoadTestsFromTipsHelper(IEnumerable`1 locations, ProjectData projectData)
       at Microsoft.VisualStudio.TestTools.TestManagement.Tmi.LoadTests(IEnumerable`1 locations, ProjectData projectData, TestConflictHandler vetoingHandler)
       at Microsoft.VisualStudio.TestTools.TestManagement.Tmi.LoadTests(String location, ProjectData projectData, TestConflictHandler vetoingHandler)
       at Microsoft.VisualStudio.TestTools.TestManagement.Tmi.LoadTests(String location, ProjectData projectData)
       at Microsoft.VisualStudio.TestPlatform.Extensions.TmiHelper.TmiDiscoveryRequest.DiscoverTests(String source, Tmi tmi)
       at Microsoft.VisualStudio.TestPlatform.Extensions.TmiHelper.TmiDiscoveryRequest.DiscoverTests(IEnumerable`1 sources, Tmi tmi)
TpTrace Information: 0 : 10032, 3, 2018/10/31, 15:22:23.257, 54721419815, testhost.x86.exe, TestDiscoveryManager.RunMessage: calling TestRunMessage(Warning, Exception has been thrown by the target of an invocation.) callback.
TpTrace Warning: 0 : 10032, 3, 2018/10/31, 15:22:23.257, 54721420131, testhost.x86.exe, Exception has been thrown by the target of an invocation.

我的想法是这个错误是在 Visual Studio 更新之后出现的,但我不能肯定地确认它。我们在 Jenkins 机器上使用 Visual Studio Community 2017 15.8.8。从 VS 运行测试不是问题。另外值得一提的是,我们仍然使用 TestSettings 并且在开始时会收到以下警告消息:

Test run will use DLL(s) built for framework .NETFramework,Version=v4.5 and platform X86. Following DLL(s) do not match framework/platform settings.
SPManagerTests.dll is built for Framework 4.5.2 and Platform AnyCPU.

但我发现这些并不是那么重要。

知道如何继续解决吗?

【问题讨论】:

    标签: c# mstest jenkins-mstest


    【解决方案1】:

    今天回过头来发现问题如下:

    • 当我没有指定 .testsettings 文件时,VsTest.Console.exe 可以执行测试
    • 当我尝试迁移到 .runsettings 时,我收到了类似的错误消息,我在 Google 上搜索过:
    Method not found: 'Void Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration.AddTestSettingsProperties(System.Collections.Generic.Dictionary`2<System.String,System.Object>)'.
    

    如果您遇到同样的问题,那么只需卸载 Visual Studio 远程工具。这解决了这两个问题。在那之前,我会尝试重新打开 MS 的问题。

    【讨论】:

      【解决方案2】:

      对于需要能够在目标机器上进行远程调试和运行测试的任何人,执行以下步骤将克服此错误:

      1. 从 KEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\Global 中删除 Microsoft.VisualStudio.TestTools.Common 条目的条目

      2. 运行“gacutil /u Microsoft.VisualStudio.TestTools.Common”

      需要第 1 步才能将其从 GAC 中删除。安装 VS Remote Tools 2017 会将有问题的 dll 添加到 GAC,这是运行测试所需的不同版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多