Sonarqube error while parsing the visualstudio.coveragexml file

Must-share information (formatted with Markdown):

SonarScanner.MSBuild.exe begin /k:“Name” /n:“Name” /“http://url” /d:sonar.login=“login” /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\VisualStudio.coveragexml"

I have opened the file VisualStudio.coveragexml in Notepad and in a browser and it shows as a valid XML file.

Getting the error:
ERROR: Error during SonarQube Scanner execution
ERROR: Error while parsing the XML file: C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml
INFO: ------------------------------------------------------------------------
The SonarQube Scanner did not complete successfully
10:21:28.283 Creating a summary markdown file…
10:21:28.289 Post-processing failed. Exit code: 1

I have attached an image of the coverage file the file.

Ruben Vilhena

I have changed the encoding of the file to be UTF-8.
I got the following error now:

ERROR: Error during SonarQube Scanner execution
ERROR: Missing root element in C:\Users\rv68115\Source\Workspaces\SSE.
ESIT\Dev\P0113 - Tender Manager\V1.1\VisualStudio.coveragexml at line 1
The SonarQube Scanner did not complete successfully
11:42:16.417 Creating a summary markdown file…
11:42:16.425 Post-processing failed. Exit code: 1

Based on this issue raised against the vstest repo, I think the SonarSource docs no longer describe the approach recommended by Microsoft.

Does it work if you omit the command
"%VSINSTALLDIR%\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" collect /output: **"%CD%\VisualStudio.coverage"**

and add the /enableCodeCoverage argument to the vstest.console.exe instead?


Hi Duncan,

thanks. That helped.
I managed to run the scan with no errors.
But I don’t see any code coverage numbers added. And the percentage still remains at 0.0%.
If I import the Unit Tests, I managed to see 112 unit tests showing in the dashboards.

So my question is:

  • How is the Code Coverage Results reflected in the Dashboard? It is just at the %?

Looking at my coveragexml file it is showing some coverage that I don’t see reflected on the Dashboard.

I am using the command:
SonarScanner.MSBuild.exe begin /k:"ProjectName" /v:"1.2" /"http://xx.xx.xx.x/sonar" /d:sonar.cs.vstest.reportsPaths="%CD%\TestResults\*.trx" /d:sonar.cs.vscoveragexml.reportsPaths="%CD%\TestResults\Visual.coveragexml"

Thank you.
Ruben Vilhena

Hi Ruben,

You should see a percentage coverage figure on the dashboard. If you drill down to view the product code you will also see green and red bars showing which lines are covered, as in the screen shot below.

Trying running the analysis specifying /d:sonar.verbose=true on the command line to increase the logging level and look at the console output for the end step. If the import is working correctly you would expect to see output like the following:

13:23:38.857 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:23:38.858 INFO: Parsing the Visual Studio coverage XML report d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.861 INFO: Adding this code coverage report to the cache for later reuse: d:\support\Scanner\coveragebug\ConsoleApp1\vs.coveragexml
13:23:38.864 DEBUG: Found some coverage info for the file 'D:\support\Scanner\coveragebug\ConsoleApp1\ConsoleApp1\Program.cs'.
13:23:38.865 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=8ms


Hi Duncan,

I added the verbose options but don’t get that result:
13:42:41.007 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:42:41.010 INFO: Parsing the Visual Studio coverage XML report C:\Users\rv6811
5\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\TestResults\VisualS
13:42:41.267 INFO: Adding this code coverage report to the cache for later reuse
: C:\Users\rv68115\Source\Workspaces\SSE.ESIT\Dev\P0113 - Tender Manager\V1.1\Te
13:42:41.267 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time

Also I can’t see any green bars, just red.



That suggests the C# test sensor can’t match any of the files listed in the coverage XML to product files it has analyzed. Could you double-check that the coverage file contains information about product files appear in SonarQube? (the coverage file may contain coverage information about test files too, but that coverage information will not be uploaded).

Also, can you repro this with a small solution that you are able to share?
I tried it locally and the coverage data was uploaded as expected.

[Update: BTW I’ve update our documentation to reflect the Mircosoft recommendations]


Hi Duncan,

I have tried to follow your approach and achieved some success.

My end goal is to load the test coverage into a SonarQube 7.6 installation I have on a server that is being used by my dev team.

To follow your recommendation I tried to import the code coverage results for a smaller project but in my local SonarQube installation.

I managed to get Cove Coverage % loaded and see them in the dashboards.

After that I tried the same with my initial project again on my local machine. And I have managed to get the results imported.

The problem is when I repeat the process on the server the results don’t get imported.

I even tried to create the project again in SonarQube but with the same result in the end.

The only differences I found are:

  • my local version is a Developer Edition (because I am trying the PL/SQL code analyser)
  • my server version has a configured url instead of the default - http://localhost:9000

Would any of these make a difference?


Finally got it working on the server.

It only worked after I restarted SonarQube.

Not sure when this should have been done. But that was the final step that made it work.

Hi Duncan,
Scanner - sonar-scanner-msbuild-
Plugin - sonar-csharp-plugin-
Code Coverage File generated by - Visual Studio 2019
i try to run vstest.console.exe and i got output like that

after that I collect the codecoverage using that
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools>CodeCoverage.exe collect /output:"C:\Sonar\DemoProject\TestResults\MyWebApp.coverage
but did not generated the .xml file or .coveragexml file
could you help me i stuck last 2 days

coverage is showing 0%

now I got the code Coverage using OpenCover Tool
1.add the opencover,Nunit,Nunit.consoleRunner,Nunit3TestAdapter after that execute Nunit.console.exe like that

2.after that execute the Opencover.console.exe file like that

3.after you add the file location in sonar-propertiese file like that



after the main report

This is the solution for generating codeCoverage and UnitTest using OpenCover and NUnit

if anyone did not get code coverage using Asp.Net Framework and visual ask me.i am always here to help you

Can you help with XUnit in sonar code coverage?

I have used XUnit our project but the Unit test result not display on the sonar dashboard.

I spent a lot of timing on this issue. So help me as soon as possible about reported issue.

Hi Vikash

am facing issue while executing the nunit3 console runner

Hi Vikash

Please share the unittestproject it will help to compare our test project any changes need to done.

we are facing issue as “Either assembly contain no test or proper test drive not found”

sathish kumar G