C# compiler crash during SonarQube analysis

SonarQube 6.7.1
SonarScanner for MSBuild 4.3.1
MSBuild 15.7

I have a VisualStudio 2017 solution. It contains many projects, including Windows Presentation Foundation (WPF) projects. The solution successfully builds under normal circumstances using MSBuild.exe.

When I try and analyse the solution using SonarScanner for MSBuild, I am getting a C# compiler (csc.exe) crash during the analysis of one of the WPF projects. I have run MSBuild with verbosity set to ‘diagnostic’ and can identify that the failure is caused by a stack overflow. Here is a short excerpt from the output generated by MSBuild:

Process is terminated due to StackOverflowException. (TaskId:8218)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(52,5): error MSB6006: “csc.exe” exited with code -1073741571. [C:\Development\Trunk\XXX\source\YYY\GUI\WPF\Resources\Resources.csproj]
Output Item(s): CscCommandLineArgs= (TaskId:8218)
Done executing task “Csc” – FAILED. (TaskId:8218)
Done building target “CoreCompile” in project “Resources.csproj” – FAILED.: (TargetId:4681)

Has this behaviour been encountered before?
Is there a solution or a work-around?

(Searching for solutions on Google etc is difficult. Any search including the words ‘stack overflow’ tends to direct me to unrelated items on a certain developer site :frowning:)

Hi @jump-jet,

We have never experienced this issue and this is the first time this is reported.

If you have admin access to your SonarQube Quality Profile, could you try to disable all rules and re-run the build with the scanner? This would allow to detect if the error is most likely to come from the analyzer or the scanner.

Also, I don’t know how big is your solution but could you try to see if building only this project (with the required dependencies) also result in the same error?

Cheers,
Amaury

Hi Amaury,

Thank you for replying. As far as disabling the rules is concerned:

I created an empty quality profile for C# and assigned it to the Sonar project.
I ran the SonarScanner.MSBuild ‘begin’ step followed by the MSBuild step to build the project. It built successfully.

I then reverted the Sonar project back onto the C# SonarWay quality profile and repeated the SonarScanner/MSBuild steps. The stack overflow exception during execution of CSC.EXE returned.

I haven’t tried your suggestion of building only the errant project. Unfortunately it is the pretty much the base project for the solution, so it depends on nearly all of the other projects that are present within the solution.

I suppose the next thing is to perform a binary-chop on the rules from the SonarWay C# quality profile to try and isolate an individual rule that is causing the problem…

Sadly I don’t see any better way. You might want to start by removing the following rules (more likely to cause the issue):

  • S1944
  • S2259
  • S2583
  • S2589
  • S3655
  • S3966
  • S4158

Cheers,
Amaury

Hi,

are there any news for this? I am faced with exactly the same problem.

best regards

I haven’t had a chance to investigate any further and isolate the rule or rules that are causing this. It is on my (long) list of things to do. Keep watching this space…

I updated from 6.7 to 6.7.5. The problem is gone!

Hi @jump-jet,

Could you confirm the issue is also fixed for you?

Cheers,
Amaury

Hi,

I have upgraded the C# plugin (leaving Sonar itself at the current long-term stability version) and so far so good. You can close this as far as I am concerned. I will re-open or start another thread if I encounter further problems.

Thanks for your help.