Could not load file or assembly Microsoft.VisualStudio.Coverage.Analysis in Visual Studio 2019 16.2
Asked Answered
U

2

13

I recently installed VS2019 Prof 16.2 and experience following error when loading .coverage files:

Microsoft Visual Studio
Exception was thrown: Could not load file or assembly 'Microsoft.VisualStudio.Coverage.Analysis,
Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.

I know that usually it meant (for previous VS versions) that you need to run tests first and then load coverage file, but now for 2019 16.2 it doesn't work. However, loading this same coverage file works in VS2017 Community 15.9.14

The Microsoft.VisualStudio.Coverage.Analysis.dll is located in C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform and has version 16.0.28223.3002

Is somebody else experiencing this issue?

A test project configured to reproduce issue can be found on my git https://github.com/miqm/playground/tree/master/SchedulingApp
To generate .coverage I run dotnet test -s Default.runsettings and then I use File -> Open to load it to VS.

I tried to run VS with /logs enabled but nothing meaningful came up. Only logs around the time I tried to open coverage are those:

<entry>
    <record>777</record>
    <time>2019/08/03 20:48:17.804</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Begin package load [Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]</description>
    <guid>{A9405AE6-9AC6-4F0E-A03F-7AFE45F6FCB7}</guid>
  </entry>
  <entry>
    <record>778</record>
    <time>2019/08/03 20:48:18.097</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Begin package load [Microsoft.VisualStudio.TestTools.Tips.TuipPackage.TuipPackage, Microsoft.VisualStudio.QualityTools.Tips.TuipPackage, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]</description>
    <guid>{52CBD135-1F97-2580-011F-C7CD052E44DE}</guid>
  </entry>
  <entry>
    <record>779</record>
    <time>2019/08/03 20:48:18.152</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>End package load [Microsoft.VisualStudio.TestTools.Tips.TuipPackage.TuipPackage, Microsoft.VisualStudio.QualityTools.Tips.TuipPackage, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]</description>
    <guid>{52CBD135-1F97-2580-011F-C7CD052E44DE}</guid>
  </entry>
  <entry>
    <record>780</record>
    <time>2019/08/03 20:48:18.164</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>End package load [Microsoft.VisualStudio.TestTools.TestCaseManagement.QualityToolsPackage, Microsoft.VisualStudio.QualityTools.TestCaseManagement, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]</description>
    <guid>{A9405AE6-9AC6-4F0E-A03F-7AFE45F6FCB7}</guid>
  </entry>

Any help appreciated.

Unseen answered 3/8, 2019 at 20:55 Comment(1)
I placed bug report to Microsoft - developercommunity.visualstudio.com/content/problem/676360/… Current state is that it was a bug that it was working all those years before for non-enterprise SKUs. But let's wait for their final response.Unseen
U
35

Microsoft response

According to Microsoft response on bug report (https://developercommunity.visualstudio.com/content/problem/676360/cannot-open-coverage-file-from-visual-studio-2019.html) it turns out, that opening Coverage files is feature of Enterprise edition only.

Reason why it was (and is) working on 2017 Community and Professional and 2019 <16.2 was a glitch, that after running all tests, the missing assembly was loaded and coverage could be opened.

TL;DR:

To bring back opening coverage files on Professional (and perhaps Community as well, didn't test it), we need to add ;Extensions\TestPlatform at the end of <probing privatePath=""/> list in %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\16.0_somehash\devenv.exe.config file.

or....

Copy

Common7/IDE/Extensions/TestPlatform/Microsoft.VisualStudio.Coverage.Analysis.dll
Common7/IDE/Extensions/TestPlatform/Microsoft.VisualStudio.Coverage.Interop.dll

to

Common7/IDE/PrivateAssemblies

Background

To open coverage file, as error states, dll file is required. That file, in Enterprise Edition, is located and loaded from: Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.Coverage.Analysis.dll

However, same file is in Common7\IDE\Extensions\TestPlatform. So we have required assembly file, but devenv doesn't know it is there.

In %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\ there are subfolders like 16.0_hash which contain devenv.exe.config files specifying required assembles and their locations.
In each of the file there's also <probing> entry that specifies additional locations to tell devenv.exe where to look for dll assemblies. Enterprise and Professional has equal entry, but since Enterprise version has missing file in PrivateAssemblies folder, which is on this list, devenv is loading it. So we need either to copy dll files from TestExtensions to PrivateAssemblies or add the folder path to probing list.

Unseen answered 1/9, 2019 at 9:27 Comment(6)
This works, but needs to be done after every VS update. q-:Fulgurous
I can confirm it works also for community editions, thank you a lot :)Oud
Copying the files survived the update from 16.4.5 to 16.5.4 in my case.Heurlin
I have VS 2019 Community edition and faced the same problem and doing this trick solved my problem. Thanks @UnseenCursory
FYI: I've been using this hack successfully with Visual Studio 2019 Professional. As of v16.9.x, however, this no longer appears to work. Notably, the TestPlatform folder no longer contains the *.Analysis.dll or *.Interop.dll assemblies; instead, it now has a *.CoreLib.Net.dll—alongside *Monitor.dll and *Interprocess.dll in subfolders—none of which satisfy the requirements of the code coverage plugin.Petepetechia
I ended up working around this new limitation by installing (a trial of) Visual Studio Enterprise v16.9.x, copying the libraries from its PrivateAssemblies directory to that of Visual Studio Professional, and then uninstalling Visual Studio Enterprise. I don’t love this solution, and it introduces some licensing ambiguities—but if, like me, you find yourself in a pinch due to the sudden removal of these libraries, it’s at least a technically feasible option.Petepetechia
H
1

I got this error when: running integration tests via test explorer on VS2019.

What my problem was: Release configuration

How I fixed that: Ran tests under Debug and they got green again.

Maybe someone googled for similar issue like I did.

Hachman answered 2/6, 2021 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.