SonarQube Not Updating Report - "Line 5 is out of range for file Program.cs. File has 4 lines"

Viewed 97

I've created a .NET Core app with just 1 file - Program.cs

enter image description here

It simply prints from 1-100

for (var i = 1; i <= 100; i++)
{
    try
    {
        Console.WriteLine(i);
    }
    catch (Exception)
    {
        throw new Exception("This is a sample exception");
    }
}

I've also setup SonarQube localy and ran my first scan using the command

dotnet sonarscanner end /d:sonar.login="<TOKEN>"

It was success and I've got a report with CodeSmells (I'm conciously putting those to test SonarCube)

enter image description here

But once I corrected the code and re ran the command, I'm getting weard errors from sonar scanner. What can be the reason?

ERROR: Error during SonarScanner execution
java.lang.IllegalArgumentException: Line 5 is out of range for file Program.cs. File has 4 lines.

enter image description here

1 Answers

From https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/:

Build

Between the begin and end steps, you need to build your project, execute tests and generate code coverage data. This part is specific to your needs and it is not detailed here.

So,

dotnet sonarscanner end /d:sonar.login="<TOKEN>"

is not enough, we have to:

dotnet sonarscanner begin /k:"project-key" /d:sonar.login="<token>"
dotnet build <path to solution.sln>
dotnet sonarscanner end /d:sonar.login="<TOKEN>"

.

Related