I'm getting this error in NCrunch when running in MS Test tests:
System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext_proxy' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'.
The solution contains many a mixture of MS Test 1 and MS Test 2 projects. All the rest of those project's tests are running normally in NCrunch.
All the MS Test 1 projects are referencing the same MS Test DLL located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Checking the source control nothing appears to have changed with the project that's now failing, what could be causing this?
It turns out that the project in question was referencing one of the other test projects, and that referenced project had been changed to use MS Test 2.
The indirect reference to another version of MSTest was meant NCrunch didn't know which version of MSTest to use, which then caused the exception.
The issue took a while to surface because NCrunch was set to only run impacted tests and none of those tests had changed for a while.
A similar issue was discussed in this thread on NCrunch forum:
Your test project is referencing two different versions of MSTest. The test project directly references MSTest 2017 (Microsoft.VisualStudio.TestPlatform.TestFramework), but indirectly references an earlier version of MSTest via Voodoo.TestData (Microsoft.VisualStudio.QualityTools.UnitTestFramework). NCrunch doesn't know which version to use, so it sets up the runtime environment for the older version. This results in the TestContext constructed for the older version of MSTest being passed into an AssemblyInitialize method targeted towards the newer version, and we end up with an explosion.