VS2017 MSTestAdapter Error

I noticed some CodedUI tests on some projects won’t work in Visual Studio 2017.  It hasn’t been consistent so I’m not sure exactly when this occurs but this is the error I received:

[1/3/2018 1:53:12 PM Warning] MSTestAdapter failed to discover tests in class ‘IntegrationTests.MyTests’ of assembly ‘D:\SourcePath\IntegrationTests\bin\Debug\MyTests.dll’. Reason Could not load file or assembly ‘Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).

Ultimately I found the an issue on the VisualStudio.com forums that matched my situation:


Apparently there is a bug in VS2017 where it isn’t referencing the right version of CodedUI.  Thankful the post also offers a workaround.  We created the following PowerShell script to apply the workaround:

#Run in PowerShell as Admin to fix error

#”Unit Test Adapter threw exception:
#Could not load file or assembly ‘Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=, Culture=neutral…” or one of its dependencies. The system cannot find the file specified..”

[Environment]::SetEnvironmentVariable(“__UNITTESTEXPLORER_VSINSTALLPATH__”, “C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE”, “Machine”)

All it does is add a new machine-level environment variable.  You will need to run the script in a PowerShell prompt with admin rights.

Leave a Reply