question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to instrument module - due to Microsoft.Extensions.DependencyInjection.Abstractions

See original GitHub issue

I try to run coverage with a .Net 5 NUnint test project using Coverlet collector 3.0.3. The project is not producing coverage project under test but for referenced class libraries there are coverage.

I’m running the following command: dotnet test <MY_TEST_PROJECT> --collect:"XPlat Code Coverage" --diag:log.txt

When examining the data collector log it seems to be related to Microsoft.Extensions.DependencyInjection.Abstractions is missing:

TpTrace Verbose: 0 : 36966, 1, 2021/03/01, 22:24:13.727, 4049879208140, datacollector.dll, [coverlet]TryWithCustomResolverOnDotNetCore exception: System.InvalidOperationException: Cannot find reference assembly 'WindowsBase.dll' file for package WindowsBase
   at Microsoft.Extensions.DependencyModel.Resolution.ReferenceAssemblyPathResolver.TryResolveAssemblyPaths(CompilationLibrary library, List`1 assemblies)
   at Microsoft.Extensions.DependencyModel.Resolution.CompositeCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List`1 assemblies)
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver[] customResolvers)
   at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.TryWithCustomResolverOnDotNetCore(AssemblyNameReference name) in /_/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 157
TpTrace Warning: 0 : 36966, 1, 2021/03/01, 22:24:13.728, 4049879564668, datacollector.dll, [coverlet]Unable to instrument module: /Users/sensitive_path/sensitive.dll because : AssemblyResolutionException for 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Try to add <PreserveCompilationContext>true</PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line

(A lot more of the first kind of log Cannot find reference assembly 'X.dll' file for package Y.)

I’ve tried to add <PreserveCompilationContext>true</PreserveCompilationContext> but it didn’t help.

The only thing helping has been to manually copy the file Microsoft.Extensions.DependencyInjection.Abstractions.dll to the same path as test dll /Users/sensitive_path/bin/Debug/net5.0/. That generates coverage for project under test as well.

Any advise what I’m doing wrong? I can provide more logs if necessary (just have to wash out some sensitive data)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
dea82commented, Mar 2, 2021

Running dotnet <MY_TEST_PROJECT> --collect:"XPlat Code Coverage" --diag:log.txt will output to: <MY_TEST_PROJECT>/bin/Debug/net5.0/Myapp.dll

However publish puts it’s output in: <MY_TEST_PROJECT>/bin/Debug/net5.0/publish/Myapp.dll

But publishing to the same folder, with -o, as build it works. Not really convenient in a CI-pipeline but works…

@MarcoRossignoli: Unfortunately it didn’t work by reference Microsoft.Extensions.DependencyInjection.Abstractions direct in test project. The Microsoft.Extensions.DependencyInjection.Abstractions.dll is not copied to output directory even if it’s referenced(!).

2reactions
d1820commented, Jan 4, 2022

Update: We fixed this by placing the <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" /> to the test project not instrumenting property. Even though we are still running the actually code at 5.0.0 it resolved the issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Could not load file or assembly Microsoft.Extensions. ...
I noticed in the error the Microsoft.Extensions.DependencyInjection.Abstractions 2.0.0 version was requested. Downgraded to that package in ...
Read more >
Can't run docker app in visual studio on release mode by ...
Extensions.Configuration.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Read more >
Developers - [coverlet] Unable to instrument module - NET 5
... [coverlet] Unable to instrument module: MyApi.dll because : AssemblyResolutionException for 'Microsoft.Extensions.Logging.Abstractions ...
Read more >
Tools 2021 | A Programmer with Microsoft tools
“Unable to provide System.CommandLine tab completion support unless the [dotnet-suggest] tool is first installed.” “See the following for tool ...
Read more >
yargs-parser 5.0.0-security.0 npmjs: ...
DependencyInjection.Abstractions 2.0.0, Microsoft.Extensions.FileProviders.Abstractions 3.1.7, Microsoft.Extensions.FileProviders.Composite 2.0.1,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found