coverlet: [coverlet] Unable to instrument module - NET 5 - Microsoft.Extensions.Logging.Abstractions

For some test projects, but not all, we get

/home/AzDevOps/.nuget/packages/coverlet.msbuild/3.1.0/build/coverlet.msbuild.targets(39,5): warning : [coverlet] Unable to instrument module: MyApi.dll because : AssemblyResolutionException for ‘Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. Try to add <PreserveCompilationContext></PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=’ option to the ‘dotnet test’ command-line

Tried:

  • Adding <PreserveCompilationContext>true</PreserveCompilationContext> to csprojs
  • Also pass /p:CopyLocalLockFileAssemblies=true to dotnet test
  • Included a package reference to Microsoft.Extensions.Logging.Abstractions directly in the test projects.
  • upgrade coverlet from 3.0.3 to 3.1.0

Related:

PS I hope this helps to diagnose the issue https://github.com/coverlet-coverage/coverlet/issues/1196. I have run more than 10 builds (with 10 tries), but all have the same issue 😦

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

I’m currently not that motivated to investigate that issue again, because I was waiting half a year for a release of my fix. Now, I switched (back) to MS coverage in my project… I do not have an idea except that Microsoft has changed some detail with .NET 8. IF I start investigation I would update the existing tests from net6 to net8.

It’s a ASP.NET Core 5 application with multiple projects.

I’m afraid it will take some time to create a repro.

Hi @304NotModified thanks for reporting this. We’ll take a look asap.

As additional information, I reproduce the problem in my library. Check the action associated with: https://github.com/adampaquette/Typely/pull/28.

I have the following structure: Typely.EfCore depends on Typely.Core. The project Typely.EfCore.Tests needs to instrument Typely.Core to fill the missing coverage on common functions.

Despite the fact that use publish+ref works I feel it too much as an “hack”, I prefer something more useful in every scenario. One idea I had also in past would be add a configuration that can be used by instrumentor for probing additional default directories. Something like typesresolutionpaths where a dev can in case of issues specify a list of path where to search if default paths don’t work.

PreserveCompilationContext is used to emit information on deps files and help coverlet to try to resolve libs needed by Cecil.

https://github.com/MarcoRossignoli/coverlet/blob/master/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs#L173

If you’re able to provide a repro I can try to improve this one.

I am having the same issue:

/xxx/xxx/.nuget/packages/coverlet.msbuild/3.1.0/build/coverlet.msbuild.targets(39,5): warning:
[coverlet] Unable to instrument module: xxx/xxx/xxx/xxx/xxx.dll because: 
AssemblyResolutionException for 'Microsoft.Extensions.Logging.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

As @304NotModified pointed out it seems that coverlet msbuild cannot find the DLL under bin/Debug/.net5.0. Even though the DLL is available in bin/Debug/.net5.0/refs, things only work when I manually copy the DLL file to the parent folder,bin/Debug/.net5.0. Is it the case that coverlet needs to scan the /refs folder as well to prevent this type of issue?