Unit Test Adapter threw exception: Unable to load one or more of the requested types

南笙酒味 提交于 2019-12-03 11:18:25
Chris

Just in case anyone else comes across this, for me it was because code coverage was enabled. Disabling it resolved the issue:

http://blogs.msdn.com/b/danielvl/archive/2010/02/16/enable-code-coverage-in-visual-studio.aspx

  • Open the .testsettings file
  • Under "Test Settings", click "Data and Diagnostics"
  • Uncheck "Code Coverage"
  • Hit "Apply"
Greg Burghardt

With the help of @jessehouwing's comment above, I've got this fixed. I was running into two problems.

The error I originally referenced was actually caused by mstest attempting to run the tests in a 64bit process (QTAgent.exe). I needed it to run as a 32 bit process because the project was compiled as 32 bit code on my 64 bit Windows 7 machine.

In Visual Studio 2010:

  1. Click the "Test" menu -> "Edit Test Settings" -> "Local (local.testsettings)"
  2. Click "Hosts" in the left hand panel
  3. Make sure "Force tests to run in 32 bit process" is chosen in the "Run tests in 32 bit or 64 bit process" drop down. For me this was the default
  4. In the Visual Studio Command Prompt, run the tests by referencing the local.testsettings file generated by Visual Studio:

    mstest /testcontainer:foo.dll /testsettings:"path/to/solution/local.testsettings" /test:SpecFlowFeatureName
    

The second problem I had was my own fault. Earlier I was playing around with Coded UI tests and SpecFlow and had installed SpecBind, which threw a bunch of settings in App.config for my test project. This NuGet package is only for .NET 4.5, and we use .NET 4.0. I removed that NuGet package and settings from App.config, cleaned and rebuilt. This fixed this issue completely.

So in short, I:

  • Forced mstest to run in a 32 bit process, and referenced this local.testsettings file from the command line
  • Removed all references to SpecBind because I got a little NuGet-happy earlier and installed a package incompatible with my .NET runtime.

As you can see by looking at the assembly references required by these packages (I use Reflector for this, but IlSpy or JetBrains' DotPeek will work as well), you'll see that they depend on the v11 version, which is the version that ships with Visual Studio 2012. These can't be used in Visual Studio 2010.

Removing SpecBind will probably help, or finding a version that depends on an older version of CodedUI (you're probably looking for a much older version of SpecBind in this case).

As for your 32-bit issue, you should probably set your project's CPU configuration to AnyCPU, there is normally no need to fix it to x86, unless you're dependent on native methods or if you're referencing other assemblies that are specifically set to use x86 as their target architecture.

Nabil Shaik

This is so troubling.....

I had Test Agent for Visual Studio 2015 installed on my test machine, since we were planning to use it - while on my local machine I had 2013. The tests ran so perfectly with MsBuild on local, that I couldn't understand what could have happened given that I always assumed Microsoft always maintained backward compatability.

MsBuild on test server failed to give any information as to what assemblies were missing (I added Newtonsoft.Json just because it complained initially, but after that I never saw the names of anything else missing). The error message was truncated, stacktrace and debugtrace options never worked...

Once I installed Test Agent for Visual Studio 2013 on the test machine, it ran like a charm.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!