Code Coverage line number error

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
  • Scanner command used when applicable (private details masked)
  • Languages of the repository
    C#, Typescript, TSQL
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    I’m trying to import Code Coverage data & I’m getting an error that the line numbers don’t match the files.
    We use NCrunch to run the unit tests & it outputs a OpenCover xml file. The NCrunch team have confirmed the OpenCover file looks right (OpenCover report - Daily Usage Issues - NCrunch Forum), yet Sonar throws an error. The error isn’t limited to just this file, it can be whatever file Sonar decides to start with.

It feels like an off-by-one error.

INFO: Sensor C# Tests Coverage Report Import [csharp]
19:08:08   INFO: Parsing the OpenCover report E:\BuildAgent\work\727bac85dde6f437\NCrunchResults\OpenCover.xml
19:08:09   INFO: Adding this code coverage report to the cache for later reuse: E:\BuildAgent\work\727bac85dde6f437\NCrunchResults\OpenCover.xml
19:08:20   INFO: Time spent writing ucfgs 16349ms
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   INFO: Total time: 4:33.904s
19:08:25   INFO: Final Memory: 76M/296M
19:08:25   ERROR: Error during SonarScanner execution
19:08:25   INFO: ------------------------------------------------------------------------
19:08:25   java.lang.IllegalStateException: Line 23 is out of range in the file project/Validators/EmailTemplateModelValidator.cs (lines: 22)
19:08:25     at org.sonar.api.utils.Preconditions.checkState(
19:08:25     at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(
19:08:25     at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyzeCoverage(
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.analyze(
19:08:25     at org.sonar.plugins.dotnet.tests.CoverageReportImportSensor.execute(
19:08:25     at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(
19:08:25     at org.sonar.scanner.sensor.ProjectSensorsExecutor.execute(
19:08:25     at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(
19:08:25     at org.sonar.core.platform.ComponentContainer.startComponents(
19:08:25     at org.sonar.core.platform.ComponentContainer.execute(
19:08:25     at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(
19:08:25     at org.sonar.core.platform.ComponentContainer.startComponents(
19:08:25     at org.sonar.core.platform.ComponentContainer.execute(
19:08:25     at org.sonar.batch.bootstrapper.Batch.doExecute(
19:08:25     at org.sonar.batch.bootstrapper.Batch.execute(
19:08:25     at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(
19:08:25     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
19:08:25     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
19:08:25     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
19:08:25     at java.base/java.lang.reflect.Method.invoke(
19:08:25     at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(
19:08:25     at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)
19:08:25     at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(
19:08:25     at org.sonarsource.scanner.api.EmbeddedScanner.execute(
19:08:25     at org.sonarsource.scanner.cli.Main.execute(
19:08:25     at org.sonarsource.scanner.cli.Main.execute(
19:08:25     at org.sonarsource.scanner.cli.Main.main(
19:08:25   ERROR:
19:08:25   The SonarScanner did not complete successfully
19:08:25   19:08:25.775  Post-processing failed. Exit code: 1
19:08:25   Process exited with code 0

  • Steps to reproduce
  • Potential workaround

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi @simongh,

Thanks a lot for your feedback. Would it be possible to create a reproducer for us? If not, would it be possible to share the code file and the generated coverage?


let me see what I can do. I’m sure I can find a file without anything we can’t share in it

Hello @simongh

In addition, could you please share the debug logs with us?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)