简体   繁体   中英

Type load exception during discovering MSTest Framework tests

Recently when we tried to run test with MSTest from Jenkins we received a 'TargetInvocationException' error. Today I switched from MSTest to VsTest.Console.exe and although I was able to get a more detailed error message, the problem is the same.

I couldn't find any indication on Google what can cause this exception. If I understand it right then the exception does not come from our tests rather from the MSTest Framework.

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.

My idea is that this error came after a Visual Studio update, but I cannot certainly confirm it. We use Visual Studio Community 2017 15.8.8 on our Jenkins machine. Running the tests from VS isn't a problem. Also worth mentioning that we still use TestSettings and we receive the following warning message at the start:

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.

But I found that these are not that really important.

Any idea how to proceed to the solution?

Today I went back to the problem and found the following:

  • VsTest.Console.exe could execute tests when I did not specify a .testsettings file
  • While I tried to migrate to .runsettings I received a similar error message that I googled:
 Method not found: 'Void Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration.AddTestSettingsProperties(System.Collections.Generic.Dictionary`2<System.String,System.Object>)'. 

If you are facing the same issue you, then just uninstall the Visual Studio Remote Tools. This solves both problems. Until then I try to reopen the issue with MS.

For anyone who needs to be able to remote debug and run tests on the target machine, performing the steps below will get past this error:

  1. Remove the entry for the entry for Microsoft.VisualStudio.TestTools.Common from KEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Installer\\Assemblies\\Global

  2. run 'gacutil /u Microsoft.VisualStudio.TestTools.Common'

Step 1 is required to allow it to be removed from the GAC. The installation of VS Remote Tools 2017 adds the offending dll to the GAC which is a different version that the one needed for tests to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM