Analysis Error "Line x out of range" with Partial Classes CSharp

csharp
scanner

(Lukas Tomalla) #1

Hey SonarQube Team,

At first, we like to use Sonarqube for our Projects and the new Pull Request feature is awesome.

Version:
We are using the Sonarqube 7.2.1 Developer Edition with the C# Plugin and TFS 2017 with the Sonarqube Extension 4.3.2

Error:
In our legacy code we used a lot of Partial Classes (2 - 3 files for a Class).
They are in different Folders, but they use the same physical filename.

Example
Wrapper/MyClass.cs
Generator/oracle/MyClass.cs
Generator/mysql/MyClass.cs

The “Run Code Analysis” Task failed with an
“Line x is out of range in the xy.cs (lines: 237)”

I think the Problem is, that all filenames are stored in a List.

Exluding the Folder “Wrapper” and “Generator” fix this Problem.

Steps to reproduce

  1. Create an CSharp Project
  2. Create two Subfolder ( A and B)
  3. Add Class “MyClass” in Subfolder “A”
  4. Add Class “MyClass” in Subolfder “B”
  5. Make both classes Partial
  6. Set both classes in the same Namespace
  7. Add a Methode to the “MyClass” in Subfolder “B”
  8. Run Analysis

(Valeri Hristov) #2

I apologize for the terribly late answer, it seems that this thread slipped out from our todo somehow…

I have difficulty reproducing the problem using the attached project partial-classes.txt (please rename the file to ZIP after downloading), I tried to follow your instructions as close as possible and I also added a few other plausible cases:

A\
    Class1.cs // empty partial class, single line
    Class2.cs // partial class with one partial method declaration, single line
    Class3.cs // partial class with one method (non-partial)
B\
    Class1.cs // partial class with one method (non-partial)
    Class2.cs // partial class with one partial method implementation
    Class3.cs // empty partial class, single line (e.g. same as Class1, but in opposite dir)

I tried with various versions of SonarQube - 7.2, 7.4, 7.6 (latest at the time of writing), SonarC# - 7.2, 7.10 (latest), Scanner for MSBuild 4.3.1, 4.5 (latest) but to no avail. I suspect that the raised issues in this class are important, so in case you are still experiencing this problem, could you please try the attached project and let me know if it appears in it?

Kind regards and I apologize one more time,
Valeri