Unable to import Coverage from VisualStudio - Error while parsing XML file

Hi SonarQube,

I am trying to import coverage of a c# project into SQ using coveragexml file, however getting a message in log:

23:52:30.045 INFO: -------------------------------------------------------------
-----------
23:52:30.046 INFO: EXECUTION FAILURE
23:52:30.115 ERROR: Error during SonarQube Scanner execution
23:52:30.046 INFO: -------------------------------------------------------------
-----------
23:52:30.046 INFO: Total time: 12.842s
23:52:30.111 INFO: Final Memory: 15M/412M
23:52:30.115 INFO: -------------------------------------------------------------
-----------
23:52:30.120 ERROR: Error while parsing the XML file: C:\Temp\Development\McK Fi
rmFormat\McKinsey.FirmFormat-insiders\TestResults\VisualStudio.coverage
Process returned exit code 1
The SonarQube Scanner did not complete successfully
23:52:30.211  Creating a summary markdown file...
23:52:30.213  Post-processing failed. Exit code: 1

The XMl file has been validated via several XML validators without any issue.

Have launched localhost version of SQ v 7.3 and getting the same issue.

Are there any logs for parsing the XML, that will give me a clear answer where the issue is? Any ideas/thought more than welcome.

Here are commands I use to build the project:

REM Initiate the SQ

SonarScanner.MSBuild.exe begin /d:sonar.verbose=true /k:"mck_firm_format_insiders" /n:"McKinsey Firm Format-insiders" /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\TestResults\*.coverage" /d:sonar.cs.vstest.reportsPaths="%CD%\TestResults\*.trx"

REM Build the project

MSBuild.exe mckinsey.firmformat.sln /t:Rebuild```

REM Run tests

"%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /Logger:trx "McKinsey.PowerPoint.UnitTests\bin\Debug\McKinsey.PowerPoint.UnitTests.dll"

"%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /Logger:trx "McKinsey.Logger.UnitTests\bin\Debug\McKinsey.Logger.UnitTests.dll"

"%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /Logger:trx "McKinsey.Registry.UnitTests\bin\Debug\McKinsey.Registry.UnitTests.dll"

REM CodeCoverage

"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output:"%CD%\TestResults\VisualStudio.coverage" "%VSINSTALLDIR%\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "McKinsey.PowerPoint.UnitTests\bin\Debug\McKinsey.PowerPoint.UnitTests.dll"

"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:"%CD%\TestResults\VisualStudio.coveragexml" "%CD%\TestResults\VisualStudio.coverage"

REM End SQ and import results

SonarScanner.MSBuild.exe end

SQ versions tested [Version 6.7.3 (build 38370)] and [Version 7.3]

David,

I see two potential issues:

  1. You should make sure you’re passing a .coveragexml file to sonar.cs.vscoveragexml.reportsPaths, the one that appears to be produced in the very last step before SonarScanner.MSBuild.exe end. It looks like you are passing a .coverage file, which SonarQube would have a hard time parsing if it thinks it should be parsing XML.
  2. Your report path has a space in it, and I have seen some other posts on this forum where that has been identified as potentially causing an issue importing code coverage reports.

Colin

1 Like

Hi Colin,

I cant believe it has been so simple. I have definitely been passing the coverage file instead of the coveragexml!

Dont even know how to thank you!

David

2 Likes