coverlet: TypeLoadException error (DependencyInjection) with latest EFCore
Hi,
I noticed that if I upgrade my EF Core libraries to latest (6.0.10), I get an error with coverlet:
Data collector 'XPlat code coverage' message: [coverlet]System.TypeLoadException: Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.GetDefaultServiceCollection(TestPlatformEqtTrace eqtTrace, TestPlatformLogger logger, String testModule)
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionStart(Object sender, SessionStartEventArgs sessionStartEventArgs) in /_/src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs:line 132.
I’m trying to upgrade Microsoft.EntityFrameworkCore from 6.0.9 to 6.0.10. My project is latest .NET 6.
Is this happening to anyone else? Is there a fix?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 13
- Comments: 27
3.2.0 released
By the end of the week I should be able to release a minor release
@MarcoRossignoli Thanks, everythings works properly
Merged so will get into the nightly builds now: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md
Actually, I think it’s Microsoft.Extensions.DependencyInjection 6.0.1 that is problematic (as a dependency of both EF Core and coverlet). Downgrading to 6.0.0 solved the problem in our Azure pipelines.
How fast can this be released? We have only 1 week to get this in or we need to downgrade Microsoft NuGets again. Thx
Got the same issue. When calling dotnet test with --collect:XPlat Code Coverage I get the error
Data collector 'XPlat code coverage' message: [coverlet]System.TypeLoadException: Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollection' from assembly 'Microsoft.Extensions.DependencyInjection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. at Coverlet.Collector.DataCollection.CoverletCoverageCollector.GetDefaultServiceCollection(TestPlatformEqtTrace eqtTrace, TestPlatformLogger logger, String testModule) at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionStart(Object sender, SessionStartEventArgs sessionStartEventArgs) in /_/src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs:line 132.It must be related to DependencyInjection 6.0.0 not being present in our project anymore. Funnily enough when using CollectCoverage=true in dotnet test, which causes it to use msbuild it didnt have that issue.
Yes, we have the same issue, I can confirm that we also updated all Microsoft & EF Core packages today, however, I haven’t check if it is related as our pipelines didn’t break. But if @leodip has it already figured out, that EF Core is the issue, it is most likely same reason for us.
Which is very good and helps us
@cheesi cool thanks. I’ll create a PR for this and try to discuss it with the other maintainers. @MarcoK80 a release in the next week is really unlikely. But maybe we can get a solution merged which then can be consumed by referencing our nightly build version.
@KlemensGenetec thanks for the repro. I’m not 100% sure what exactly the problem is yet, but it is definitely related to the change @candritzky mentioned here:
Coverlet currently references both
Microsoft.Extensions.DependencyInjectionandMicrosoft.Extensions.DependencyInjection.Abstractionswhich somehow leads to incompatibilities with theServiceCollectionin the new version.I compiled a new version of coverlet that at least solved this issue for the repro. I would be happy if someone could give it a try. 😄
coverlet.3.1.3-preview.16.zip
Happens because of the updated Microsoft.Extensions.DependencyInjection NuGet package (now version 6.0.1). This results in a newer Microsoft.Extensions.DependencyInjection.dll being copied to the bin folder (still assembly version 6.0.0.0).
If you either delete the DLL from the bin folder before running the tests, or if you manually copy Microsoft.Extensions.DependencyInjection.Abstractions.dll (from NuGet package 6.0.0 which is still latest) to the bin folder, then code coverage is working again.
Really strange…