Sonarscanner Detects C++ code for C# codebase

Using developer edition SonarQube 9.5 (build56709) and Sonarscanner for msbuild 5.7.0.
While doing the scan on our .Net 4.7.1 code which only contains C# code am getting this error which suggests I have C/C++ code and wants me to exclude it. Being fairly new to SonarQube I tried the global exclusion as well in the administration panel but i still get this error. I also tried adding the suffixes exclusion which was suggested in the error in .sonarqube\out\sonar-project.properties file, but that also didnt work.

Edit: Not sure if it’s relevant but I never got this error when I tried scanning with community edition of sonarqube 8.9.8.

ERROR: Error during SonarScanner execution
INFO: ------------------------------------------------------------------------
java.lang.UnsupportedOperationException:

The only way to get an accurate analysis of C/C++/Objective-C files is by using the SonarSource build-wrapper and setting the property "sonar.cfamily.build-wrapper-output" or by using Clang Compilation Database and setting the property "sonar.cfamily.compile-commands". None of these two options were specified.

If you don't want to analyze C/C++/Objective-C files, then prevent them from being analyzed by setting the following properties:

    sonar.c.file.suffixes=-
    sonar.cpp.file.suffixes=-
    sonar.objc.file.suffixes=-


        at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:253)
        at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:203)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
        at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:81)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:392)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:388)
        at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:357)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:135)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at com.sun.proxy.$Proxy0.execute(Unknown Source)
        at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
        at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
        at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
The SonarScanner did not complete successfully
16:28:28.778  Post-processing failed. Exit code: 1

Hi,

Welcome to the community!

I’ll go backward & start by saying you didn’t see this in 8.9.8, Community Edition because Community Edition doesn’t offer C++ analysis. It simply ignored the files in question.

It’s not clear to me what you tried. A screenshot or snippet might be helpful. But did you try what the error message suggests? I.e. adding this to your analysis parameters?

What’s happening here is that analysis - which now recognizes C, C++ & Objective-C files - is seeing something it thinks should be analyzed a one of those languages. And it’s “recognizing” those files based on file suffix. The error message is suggesting you set the list of recognized file suffixes for each of these languages to -, so that no files will be identified as C, C++ or Objective-C. And that will allow your analysis to proceed.

 
HTH,
Ann

I added the file list in the following setting:

But this doesn’t seem to help or am understanding the purpose of this wrong.

I tried to add this to .sonarqube\out\sonar-project.properties file but it seems every time i run the scan the file gets rewritten and the settings you mentioned disappear. Now I am not sure if this is the right place to do or not. Any help in guiding me to correct file where I should put these settings would be great.

Thanks,
SK

Hi,

Analysis owns what’s in the .sonarqube directory (which was created by a previous analysis). I’m not surprised it gets overwritten each time. You should also have a sonar-project.properties file in your project root…? Add the properties there.

Regarding the exclusions you set, those fields are expecting patterns
that describe file paths. This is not the place for just listing file extensions.

Either you need to set your exclusions to **/*.c &etc, or you need to set the “file suffixes” inputs on Languages → C / C++ / Objective-C to .c &etc. These are not interchangeable. Or you need to set those properties in your sonar-project.properties file in the project root.

 
HTH,
Ann

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