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

SonarScanner for MSBuild 5.4.1
SonarScanner 4.6.2.2472
SonarQube server 9.2.4
Java 17.0.1 Oracle Corporation (64-bit)

Link to StackOverflow issue: c# - SonarQube Not Updating Report - "Line 5 is out of range for file Program.cs. File has 4 lines" - Stack Overflow

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

The only code in Program.cs is:

for (var i = 1; i <= 100; i++)
{
    try
    {
        Console.WriteLine(i);
    }
    catch (Exception)
    {
        throw new Exception("This is a sample exception");
    }
}
  1. I’ve also setup SonarQube locally and ran my first scan using the command
    dotnet sonarscanner end /d:sonar.login=""
  2. It was success and I’ve got a report with CodeSmells (I’m conciously putting those to test SonarCube)
  3. But once I corrected the code and re ran the command, I’m getting weird errors from sonar scanner

What are your scan settings, and do you have code coverage enabled for this? I seem to remember similar issues in the past when there was an outdated code coverage report involved.

Do you clear out all old build artifacts when building your project?

1 Like

Hi Chris, Thanks for your query.
I’ve figured out the issue. This is happenning because I’m running the command

“dotnet sonarscanner end /d:sonar.login=”""

multiple times.
Now I’m running these 3 commands serially to test it again. These are not very well documented and thus became new adopters to SonarQube like me will become extremally confused. These are the 3 commands now I’m running and I’m happy with the reports.

dotnet sonarscanner begin /k:"" /d:sonar.login=""
dotnet build
dotnet sonarscanner end /d:sonar.login=""

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.