Despite following the recommendation of using the following command:
dotnet test --collect:"XPlat Code Coverage"
Because of this known issue https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md#1-vstest-stops-process-execution-earlydotnet-test
I still seem to be getting the same issue.
Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to get coverage result
---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.InternalRead(Int32 numBytes)
at Coverlet.Core.Coverage.CalculateCoverage() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 363
at Coverlet.Core.Coverage.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.core\Coverage.cs:line 137
at Coverlet.Collector.DataCollection.CoverageWrapper.GetCoverageResult(Coverage coverage) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageWrapper.cs:line 44
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 91
--- End of inner exception stack trace ---
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverageManager.cs:line 96
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionEnd(Object sender, SessionEndEventArgs e) in D:\git\coverletToRelease\src\coverlet.collector\DataCollection\CoverletCoverageCollector.cs:line 148.
Is it expected that by using this method I should never get the Unable to read beyond the end of the stream error?
Is it expected that by using this method I should never get the Unable to read beyond the end of the stream error?
No
Are you sure to setup all correctly? https://github.com/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md
If so can you share your test project csproj?
It's been working well on build agents so I think it maybe something with my local setup. I'll see if I can reproduce tomorrow.
Be sure to update test sdk package to preview (for now) like in the sample on guide otherwise in process collector won't be loaded and you'll could hit that issue. That issue is randomic and depends on timing and machine load.
any news?
Facing the same issue. It is not consistent though.

The screenshot is from our build agent logs. When I just retry without making any changes, it works. Please let me know if you need any further info.
~@prashanth-nani can you show you test project references and the command line you use to run coverage?~
Sorry you're hitting known issue for msbuild...you have to use collectors
Issue https://github.com/tonerdo/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test
Collectors https://github.com/tonerdo/coverlet/blob/master/Documentation/VSTestIntegration.md
Collectors today doesn't support merge
@pape77 I cannot find your workaround to use merge with current version of collector...can you paste the link here?
@MarcoRossignoli it's in a closed pr
https://github.com/tonerdo/coverlet/pull/225#issuecomment-573896446
Thank's, @prashanth-nani if you want to use merge with collector(that feat was hidden because is not so easy to use/understand at the moment) you can use Daniel trick!
Thanks @MarcoRossignoli, I'll take a look at it.
@prashanth-nani any news?Feel free to close if solved!
Sorry for the delay. As this is a known issue, I'm gonna close this. Thanks a lot for pointing me to the right resources. 馃檪
Edit: I'm not the author of this issue. So I cannot close it.
Close for stale conversation and solved issue, feel free to reopen if needed!
Hello, I wanted to reopen this issue as we are experiencing the same problem using the collectors. Our package version are the following:
We run the tests by running dotnet test {CS Project} --no-build --no-restore --logger trx --collect "XPlat Code Coverage".
The error we receive is:
Data collector 'XPlat code coverage' message: [coverlet]Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to get coverage result
---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.InternalRead(Int32 numBytes)
at Coverlet.Core.Coverage.CalculateCoverage() in /_/src/coverlet.core/Coverage.cs:line 367
at Coverlet.Core.Coverage.GetCoverageResult() in /_/src/coverlet.core/Coverage.cs:line 141
at Coverlet.Collector.DataCollection.CoverageWrapper.GetCoverageResult(Coverage coverage) in /_/src/coverlet.collector/DataCollection/CoverageWrapper.cs:line 44
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in /_/src/coverlet.collector/DataCollection/CoverageManager.cs:line 93
--- End of inner exception stack trace ---
at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageResult() in /_/src/coverlet.collector/DataCollection/CoverageManager.cs:line 98
at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionEnd(Object sender, SessionEndEventArgs e) in /_/src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs:line 160.
The test projects are being run one by one. This does not happen all the time, hence our coverage is inconsistent.
Pls can you open a new issue with same infos?
Please reopen. Getting the same error.
dotnet version: 3.1.302
Command:
bat "${env.DOTNET_EXE} test MyTestProject.csproj --no-restore -c Release /p:CollectCoverage=true /p:CoverletOutput=${env.WORKSPACE}/${env.UT_RESULTS} /p:CoverletOutputFormat=opencover /p:Threshold=50 /p:ThresholdType=branch /p:ThresholdStat=Average /p:Exclude=[*Test*]*"
@agray you should try to use collector integration that is a known issue for msbuild integration https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/KnownIssues.md#1-vstest-stops-process-execution-earlydotnet-test
Please open new issue if issue persist also after collectors switch