Coverlet: Failed to resolve assembly

Created on 20 Sep 2019  Â·  21Comments  Â·  Source: coverlet-coverage/coverlet

I have a .Net Core 2.2 project using xUnit 2.4.0, the SonarScanner for MSBuild 4.7.1, and coverlet.msbuild 2.6.3 to measure code coverage of my unit tests. The project also uses Nest 6.4.0 (Elasticsearch high-level client for C#) and other related packages. The code and unit tests all work fine without the coverlet.msbuild package dependency.

When I add the coverlet.msbuild package dependency to my unit tests project, I get an error from coverlet.msbuild:

C:\Users\robert.h.patrick\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(7,5): warning : [coverlet] Unable to instrument module: d:\src\cap\case-service\case-service.Tests\bin\Release\netcoreapp2.2\case-service.dll because : Failed to resolve assembly: 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [d:\src\cap\case-service\case-service.Tests\case-service.Tests.csproj]
Test run for d:\src\cap\case-service\case-service.Tests\bin\Release\netcoreapp2.2\case-service.Tests.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Test Run Successful.
Total tests: 47
     Passed: 47
 Total time: 1.7411 Seconds

Calculating coverage result...
  Generating report 'd:\src\cap\case-service\case-service.Tests\coverage.opencover.xml'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | ∞%   | ∞%     | ∞%     |
+---------+------+--------+--------+

SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
...

I have spent days searching, reading, and trying various solutions to resolve this.

  • I tried adding a package dependency to the project (both the normal project and the unit test project).
  • I tried the adding the /p:CopyLocalLockFileAssemblies=true option to the dotnet test command-line.

The aforementioned DLL is present in multiple locations on my local machine:

  • C:\Users\robert.h.patrick\.nuget\packages\microsoft.extensions.logging.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll
  • C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.logging.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll).

The only reliable way to work around this problem is to drop the DLL in the unit tests project's bin\Release\netcoreapp2.2 directory.

I have the same problem on my Jenkins build machine running on Amazon Linux 2.

bug

All 21 comments

Can you try to add include filter https://github.com/tonerdo/coverlet/blob/master/Documentation/MSBuildIntegration.md#filters and include only dll you want?
There is an issue with transitive reference that are not moved to target output folder...but sometimes the issue is the instrumentation of unuseful lib that fire that load.
If error persist are you able to repro in a small project?So maybe we can find out a solution(something like custom loader).

I added the exclude filter and while it changed the output, the problem remains. I will continue trying to create a sample project...

D:\src\cap\case-service>dotnet test --no-build -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CopyLocalLockFileAssemblies=true /p:Exclude="[Microsoft.Extensions.Logging.Abstractions].*"
C:\Users\robert.h.patrick\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(7,5): warning : [coverlet] Unable to instrument module: D:\src\cap\case-service\case-service.Tests\bin\Release\netcoreapp2.2\case-service.dll because : Failed to resolve assembly: 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [D:\src\cap\case-service\case-service.Tests\case-service.Tests.csproj]
Test run for D:\src\cap\case-service\case-service.Tests\bin\Release\netcoreapp2.2\case-service.Tests.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Test Run Successful.
Total tests: 47
     Passed: 47
 Total time: 1.9108 Seconds

Calculating coverage result...
  Generating report 'D:\src\cap\case-service\case-service.Tests\coverage.opencover.xml'

+--------------------------------------------------+--------+--------+--------+
| Module                                           | Line   | Branch | Method |
+--------------------------------------------------+--------+--------+--------+
| xunit.runner.reporters.netcoreapp10              | 1.1%   | 0.48%  | 5.08%  |
+--------------------------------------------------+--------+--------+--------+
| xunit.runner.utility.netcoreapp10                | 15.68% | 9.14%  | 21.03% |
+--------------------------------------------------+--------+--------+--------+
| xunit.runner.visualstudio.dotnetcore.testadapter | 45.76% | 35.92% | 47.76% |
+--------------------------------------------------+--------+--------+--------+

+---------+-------------------+-------------------+--------+
|         | Line              | Branch            | Method |
+---------+-------------------+-------------------+--------+
| Total   | 23.75%            | 17.9%             | 26.55% |
+---------+-------------------+-------------------+--------+
| Average | 7.91666666666667% | 5.96666666666667% | 8.85%  |
+---------+-------------------+-------------------+--------+

I will continue trying to create a sample project...

Could be very useful a repro!

Ah another thing...try also with an "include" because exclude doesn't mean that some other instrumented lib will try to load excluded one...with include we're sure that the "wanted instrumented lib" need that load.

OK, I have a reproducer that should work outside of our environment. Since it still is loosely based on our business application, I have added you as a collaborator to the private GitHub project. Let me know if you need anything else.

I see thank's I'll take a look asap.

@rpatrick00 I found the issue...at the moment I don't have a fix, it's related to how cecil(library that we use to instrument dll) load transitive reference from .nuget packages folder.
I'll come back if found something, for now you should use the workaround of copy dll on target folder, in that way cecil found lib without problem.

Thanks!

Thank's to you for repro!

Setting CopyLocalLockFileAssemblies property helped me. Though I'm on 2.1 and referencing Microsoft.AspNetCore.App (rather than .All).

Experiencing the same issue: .Net Core 2.2 project using xUnit 2.4.1 and coverlet.msbuild 2.7.0.

/Users/user/.nuget/packages/coverlet.msbuild/2.7.0/build/coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: /Users/user/dev/Project.Tests/bin/Debug/netcoreapp2.2/Project.Api.dll because : Failed to resolve assembly: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [/Users/user/dev/Project.Tests/Project.Tests.csproj]

No luck with:

  • Adding Microsoft.Extensions.DependencyInjection.Abstractions as a specific dependency
  • Using /p:CopyLocalLockFileAssemblies=true

Hi @jeffw-wherethebitsroam I've just added this issue as "know issue" I'm in contact with msbuild team(you can read linked issue) but at the moment the only solution is to manually copy missing dll to output build folder https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md#4-failed-to-resolve-assembly-during-instrumentation

@jeffw-wherethebitsroam the issue will be resolved by design in 3.0 maybe if your project is netstandard libs and test is 2.x you can move to 3.0 only test proj.

@rpatrick00 @jeffw-wherethebitsroam guys you can test this update using nightly build, if you can I'll appreciate a lot(starting from tomorrow we publish in the night) https://github.com/tonerdo/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

Copying the file manually works.. any idea on how to copy the dll from a NuGet package?

Nevermind. For now, I'm doing a dotnet publish and copying the required file to the appropriate location. Things are working fine.

@nmarun ok, if you want to try without publishing you can try to dogfood nightly build that help to fix this issue https://github.com/tonerdo/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

coverlet.msbuild 2.8.0 fixed the issue in all but one of my projects. I updated them while migrating them to Dotnet Core 3.1 today. Haven't been able to determine what makes this one project different than all of the others yet...

Thank's @rpatrick00 could be something related to https://github.com/tonerdo/coverlet/pull/655 we're investigating...could be great if you provide another repro to understand if we're on right path and the issue is the same, at you pace no rush.
This is an hard nut to crack 😞 a lot of cases.

@MarcoRossignoli
I have a Xamarin Forms project which has unit tests written using NUnit targeting .Net Core 3.1. While trying to build the Azure pipeline for the project I am getting a similar error but for a different assembly. Please find below the logs

````
/usr/local/bin/dotnet test /Users/runner/work/1/s/App.Test/App.Test.csproj --logger trx --results-directory /Users/runner/work/_temp --configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=/Users/runner/work/1/s/TestResults/Coverage/ /p:CopyLocalLockFileAssemblies=true

/Users/runner/.nuget/packages/coverlet.msbuild/2.9.0/build/coverlet.msbuild.targets(31,5): warning : [coverlet] Unable to instrument module: /Users/runner/work/1/s/App.Test/bin/Release/netcoreapp3.1/Xamarin.Forms.Core.dll because : No symbol found for file: /Users/runner/work/1/s/App.Test/bin/Release/netcoreapp3.1/Xamarin.Forms.Core.dll [/Users/runner/work/1/s/App.Test/App.Test.csproj]

Test run for /Users/runner/work/1/s/App.Test/bin/Release/netcoreapp3.1/App.Test.dll(.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.7.0
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
Results File: /Users/runner/work/_temp/_Mac-1606664309627_2020-11-29_15_42_20.trx

Test Run Successful.
Total tests: 15
Passed: 15
Total time: 1.4592 Seconds

Calculating coverage result...
Generating report '/Users/runner/work/1/s/TestResults/Coverage/coverage.cobertura.xml'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+

+---------+------+--------+--------+
| | Line | Branch | Method |
+---------+------+--------+--------+
| Total | 100% | 100% | 100% |
+---------+------+--------+--------+
| Average | NaN% | NaN% | NaN% |
+---------+------+--------+--------+
```

Any help to resolve the issue is highly appreciated. Thanks.

@subramaniamb can you open a new issue pls, at first glance seem a different issue, the log seems not related to assembly resolution.
I'll take a look asap.

@subramaniamb can you open a new issue pls, at first glance seem a different issue, the log seems not related to assembly resolution.
I'll take a look asap.

Really appreciate your quick response. New Issue raised.

Was this page helpful?
0 / 5 - 0 ratings