Skip to content

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

@ghost

Description

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions