Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to resolve assembly #560

Closed
rpatrick00 opened this issue Sep 20, 2019 · 21 comments · Fixed by #625
Closed

Failed to resolve assembly #560

rpatrick00 opened this issue Sep 20, 2019 · 21 comments · Fixed by #625
Labels
bug Something isn't working

Comments

@rpatrick00
Copy link

rpatrick00 commented Sep 20, 2019

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.

@MarcoRossignoli MarcoRossignoli added the needs more info More details are needed label Sep 21, 2019
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 21, 2019

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).

@rpatrick00
Copy link
Author

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%  |
+---------+-------------------+-------------------+--------+

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 22, 2019

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.

@rpatrick00
Copy link
Author

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.

@MarcoRossignoli
Copy link
Collaborator

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

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 23, 2019

@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.

@MarcoRossignoli MarcoRossignoli added bug Something isn't working and removed needs more info More details are needed labels Sep 23, 2019
@rpatrick00
Copy link
Author

Thanks!

@MarcoRossignoli
Copy link
Collaborator

Thank's to you for repro!

@Vertigo093i
Copy link

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

xaviersolau added a commit to xaviersolau/ActionDispatch that referenced this issue Oct 28, 2019
xaviersolau added a commit to xaviersolau/ActionDispatch that referenced this issue Oct 29, 2019
@jeffw-wherethebitsroam
Copy link

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

@MarcoRossignoli
Copy link
Collaborator

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

@MarcoRossignoli
Copy link
Collaborator

@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.

@MarcoRossignoli
Copy link
Collaborator

@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

@nmarun
Copy link

nmarun commented Dec 31, 2019

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

@nmarun
Copy link

nmarun commented Dec 31, 2019

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

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Dec 31, 2019

@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

@rpatrick00
Copy link
Author

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...

@MarcoRossignoli
Copy link
Collaborator

Thank's @rpatrick00 could be something related to #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.

@subramaniamb
Copy link

@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.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Nov 30, 2020

@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
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants