Unable to instrument module - due to Microsoft.Extensions.DependencyInjection.Abstractions
See original GitHub issueI 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:
- Created 3 years ago
- Comments:7
Top GitHub Comments
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(!).
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