Repository navigation
Description
Describe the bug
Please share a clear and concise description of the problem.
To Reproduce
- Create WebAPI and UnitTest projects from template.
- Add Mediator packages to WebAPI project
<ItemGroup>
<PackageReference Include="Mediator.Abstractions" Version="3.0.0-preview.27" />
<PackageReference Include="Mediator.SourceGenerator" Version="3.0.0-preview.27" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers;</IncludeAssets>
</PackageReference>
</ItemGroup>- Run tests
dotnet test .\TestProject.sln --configuration Debug --collect:"XPlat Code Coverage" --diag:log.txt
Expected behavior
Coverage report includes types from analyzed project.
Actual behavior
Coverage report is empty.
<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0" branch-rate="0" version="1.9" timestamp="1734109700" lines-covered="0" lines-valid="0" branches-covered="0" branches-valid="0">
<sources />
<packages />
</coverage>Configuration (please complete the following information):
Please provide more information on your .NET configuration:
* Which coverlet package and version was used?
6.0.0
* Which version of .NET is the code running on?
net8.0
* What OS and version, and what distro if applicable?
Win11
* What is the architecture (x64, x86, ARM, ARM64)?
x64
* Do you know whether it is specific to that configuration?
No
Additional context
log.datacollector contains the following exception
TpTrace Information: 0 : 35584, 1, 2024/12/13, 18:07:37.009, 629740483105, datacollector.dll, AssemblyResolver.OnResolve: Resolved assembly: Microsoft.DotNet.PlatformAbstractions, from path: C:\Users\admin\.nuget\packages\coverlet.collector\6.0.0\build\netstandard1.0\Microsoft.DotNet.PlatformAbstractions.dll
TpTrace Verbose: 0 : 35584, 1, 2024/12/13, 18:07:37.012, 629740517319, datacollector.dll, [coverlet]AspNetCoreSharedFrameworkResolver search paths:
TpTrace Verbose: 0 : 35584, 1, 2024/12/13, 18:07:37.012, 629740517703, datacollector.dll, [coverlet]C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All\9.0.0
TpTrace Verbose: 0 : 35584, 1, 2024/12/13, 18:07:37.012, 629740517868, datacollector.dll, [coverlet]C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\9.0.0
TpTrace Verbose: 0 : 35584, 1, 2024/12/13, 18:07:37.013, 629740524572, datacollector.dll, [coverlet]Loading D:\Projects\Sandbox\Testcoverage\Testsnet8\bin\Debug\net8.0\testsnet8.deps.json
TpTrace Warning: 0 : 35584, 1, 2024/12/13, 18:07:37.017, 629740570341, datacollector.dll, [coverlet]Unable to instrument module: D:\Projects\Sandbox\Testcoverage\Testsnet8\bin\Debug\net8.0\ProjNet8.dll
Coverlet.Core.Exceptions.CecilAssemblyResolutionException: AssemblyResolutionException for 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.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
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
--- End of inner exception stack trace ---
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.TryWithCustomResolverOnDotNetCore(AssemblyNameReference name) in /_/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 215
at Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver.Resolve(AssemblyNameReference name) in /_/src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs:line 127
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
at Mono.Cecil.MetadataBuilder.AddField(FieldDefinition field)
at Mono.Cecil.MetadataBuilder.AddFields(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
at Mono.Cecil.MetadataBuilder.AddTypes()
at Mono.Cecil.MetadataBuilder.BuildTypes()
at Mono.Cecil.MetadataBuilder.BuildModule()
at Mono.Cecil.MetadataBuilder.BuildMetadata()
at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
at Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
at Coverlet.Core.Instrumentation.Instrumenter.InstrumentModule() in /_/src/coverlet.core/Instrumentation/Instrumenter.cs:line 333
at Coverlet.Core.Instrumentation.Instrumenter.Instrument() in /_/src/coverlet.core/Instrumentation/Instrumenter.cs:line 149
at Coverlet.Core.Coverage.PrepareModules() in /_/src/coverlet.core/Coverage.cs:line 135
Including <PreserveCompilationContext>true</PreserveCompilationContext> and CopyLocalLockFileAssemblies do not make any effect.
Workaround
- Add
<PreserveCompilationContext>true</PreserveCompilationContext> - Copy dependencies via AfterBuild task
<Target Name="CopyMediatorSourceGenDeps" AfterTargets="Build">
<ItemGroup>
<ResolvedFiles Include="$(OutputPath)/refs/Microsoft.Extensions.DependencyInjection.Abstractions.dll" />
</ItemGroup>
<Copy SourceFiles="@(ResolvedFiles)" DestinationFolder="$(OutputPath)" />
</Target>
Activity
Bertk commentedon Jan 10, 2025
Thanks a lot for reporting this issue. The current coverlet.collector version 6.0.3 targets netstandard2.0 only. This issue will be solved in the next major version.
alex-zyl commentedon Jan 10, 2025
Thanks for heads up @Bertk
Can't
NetstandardAwareAssemblyResolverjust be updated to try to lookup an assembly inrefsfolder if not found in main directory?Bertk commentedon Jan 11, 2025
Please you please try to use a self contained test executable. This might resolve the dependency problem.
killergege commentedon Apr 9, 2026
We have a very similar issue
In our solution, we replaced MediatR with Mediator.SourceGenerator.
Since this change, the project that references the Mediator.SourceGenerator is missing from the coverage for the project testing it.
Other side projects are there, but the main one is just missing.
There is no warning or error displayed during build or testing though. I tried to have detailed logs, but found nothing useful.
We found that 2 elements impact the issue:
We tried several combinaisons:
The suggested solution above to copy the dependency
Microsoft.Extensions.DependencyInjection.Abstractionsmanually to the output fixes the issue, but I'm not sure why:And updating the reference:
We are using Coverlet 8.0.1 (but we also have the issue with 6.0.4).
Bertk commentedon Apr 9, 2026
Thank you for sharing this information. When you have a moment, could you please try the coverlet.collector preview from the Coverlet nightly build (version 8.1.0-preview-0016-gdcc9d19f60) and let me know how it works for you?
If the issue persists, it would be very helpful if you could share the diagnostic log files so we can take a closer look.
Looking ahead, with .NET 10 it may also be worth considering a migration to the Microsoft Testing Platform along with the
coverlet.MTPNuGet package.yusyd commentedon Apr 9, 2026
@Bertk I have the same issue, and I tested the nightly collector
coverlet.collector 8.1.0-preview-0016-gdcc9d19f60. It still reproduces for me on Windows x64 with .NET SDK10.0.201.I also reproduced the same on Ubuntu in GitHub Actions CI: tests pass, Cobertura is generated, but the assembly is missing from the coverage output.
I created a standalone repro here:
https://github.com/yusyd/coverlet-mediator-repro
With this repro, tests pass and Cobertura is generated, but
Repro.Applicationis missing from the coverage outputThe datacollector log shows:
I also tried the workarounds, and none of them fixed it:
<PreserveCompilationContext>true</PreserveCompilationContext>/p:CopyLocalLockFileAssemblies=trueAStarchikov commentedon Apr 9, 2026
I have the same issue
Was able to reproduce it with @yusyd repo sample
51 remaining items
Bump coverlet.msbuild from 8.0.0 to 10.0.1 (#330)
chore(deps): Bump the test-dependencies group with 1 update (#34)
Bump coverlet.collector from 8.0.1 to 10.0.1 (#52)
kayarre commentedon Jun 4, 2026
This appears to be an issue in 10.0.1
Bertk commentedon Jun 5, 2026
Please use the latest coverlet.MTP nuget preview package 10.0.2-preview.2.gdfb154275d
coverlet.MTP is actively maintained and aligned with the Microsoft Testing Platform (MTP), which is the default test platform starting with .NET 10.
see https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test
Important
Running MTP projects under VSTest mode is considered legacy in favor of the newer experience in .NET 10 SDK. The support of running under this mode will be removed in MTP version 2 if run with .NET 10 SDK. The support remains available for .NET 9 SDK and earlier for backward compatibility. For more information, see Migrate to MTP mode of dotnet test.
Note
test example MediatorApp.Tests create test results.
chore(deps): Bump coverlet.collector from 6.0.2 to 10.0.1 (#13)
Bump coverlet.collector and 3 others (#6)
Bump coverlet.collector from 6.0.4 to 10.0.1 (#19)
Bump coverlet.collector and 7 others (#86)
chore: Bump coverlet.collector from 8.0.1 to 10.0.1 (#283)
Bump coverlet.collector from 6.0.4 to 10.0.1 (#6)
[nuget][Find]- Bump Azure.Identity and 26 others (#705)
Bump the test-dependencies group with 3 updates (#2)
Bump coverlet.msbuild from 8.0.0 to 10.0.1 (#893)
chore(deps): Bump coverlet.collector from 6.0.4 to 10.0.1 (#438)