coverlet-coverage / coverlet

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

[BUG] System.IndexOutOfRangeException using coverlet collector #1682

Closed peibol71 closed 1 month ago

peibol71 commented 1 month ago

I can't get the coverage.coverture.xml file because of this exception error

I'm using this command: dotnet test -c Release --collect:"XPlat Code Coverage"

And get this error message: Data collector 'XPlat code coverage' message: Coverlet.Collector.Utilities.CoverletDataCollectorException: CoverletCoverageDataCollector: Failed to get coverage report ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at Coverlet.Core.Reporters.CoberturaReporter.Report(CoverageResult result) at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageReport(CoverageResult coverageResult) --- End of inner exception stack trace --- at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageReport(CoverageResult coverageResult) at Coverlet.Collector.DataCollection.CoverageManager.GetCoverageReport() at Coverlet.Collector.DataCollection.CoverletCoverageCollector.OnSessionEnd(Object sender, SessionEndEventArgs e).

.NET configuration:

Any idea?

Thanks.

Bertk commented 1 month ago

Please check whether PDB files are available in the output folder.

Locates the unit test assembly and selects all the referenced assemblies that have PDBs.

https://github.com/coverlet-coverage/coverlet?tab=readme-ov-file#how-it-works

peibol71 commented 1 month ago

There is one PDB file (projectname.pdb) in projectfolder\obj\Release\net6.0 and the same and 4 others in projectfolder\bin\Release\net6.0

Bertk commented 1 month ago

Maybe diagnostic logs will provide more information.

dotnet test --collect:"XPlat Code Coverage" --settings runsettings --diag:log.txt

peibol71 commented 1 month ago

Sorry, that's not a bug. There was a misconfigured Directory.Build.props file and the project was using coverlet.collector v1.0 instead of v6.0.2

Bertk commented 1 month ago

No problem. Please close the issue.