coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.99k stars 386 forks source link

When using .NET 6 (with .NET 8 installed) picking wrong version of System.Text.Json [BUG] #1639

Closed clinington closed 8 months ago

clinington commented 8 months ago

Describe the bug So I have both sdks installed, i have a global json pinning the version to 6.0.419.

The version of coverlet.collector is 6.0.1.

Running:

dotnet test --configuration Release --filter Category!=Manual --logger trx --collect:"XPlat Code Coverage;Format=opencover,cobertura"

gets this result:

Data collector 'XPlat code coverage' message: [coverlet]System.IO.FileLoadException: Could not load file or assembly 'System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)

However, if you switch coverlet.collector to version 6.0.0 and run the same command again then the issue goes away - assuming that it has something to do with the switch from newtonsoft to system.text.json

:exclamation: Please also read Known Issues

niravmsoni commented 8 months ago

Faced the same issue in one of our pipeline after updating the package to the latest version. After downgrading it to 6.0.0, it works for me. Thanks for the workaround @clinington

patelriki13 commented 8 months ago

Same issue for me... downgraded to version 6.0.0 and working fine.

clinington commented 8 months ago

Yeah - that was my fix - then went to .net8 and bumped back up again.

However, the there's a security vulnerability with the newtonsoft package that is used by version 6.0.0 so it's not a great workaround...

daveMueller commented 8 months ago

Yes this is a duplicate of #1625. We already fixed this in #1637. You can try it out by consuming our nightly: https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/ConsumeNightlyBuild.md

daveMueller commented 8 months ago

We now have a new official release 6.0.2 that can be consumed from nuget.org.