Unable to parse file

We’re using SonarQube v9.9.2 (build 77730) being run from Azure pipeline task SonarQubeAnalyze@5.

For one of our repos we are getting the following error:

##[error]ERROR: Unable to parse file: file:///home/vsts/work/1/s/src/CompanyName.Frameworks.Testing.Architecture/TargetFramework/Dockerfile.cs. Parse error at position 1:0

I have attached the full log which contains the very simple 11 lines of code that makes up Dockerfile.cs, a very simple record containing just four properties and nothing else.

Looking at the log, the lines just before the error states:

2024-04-08T14:11:35.6787131Z INFO: Sensor IaC Docker Sensor [iac]
2024-04-08T14:11:35.6900845Z INFO: 1 source file to be analyzed

There is nothing wrong with the C# file and its language version is supported by this version of SonarQube. Is it possible that SonarQube is treating this file like a Dockerfile rather than a C# file purely because of its name? Although a Docker file would typically not have a .cs file extension.

If not, what else could be the problem with this file?

Thanks!

Hello @MintFroggery!

Thanks for your report. Unfortunately, the discovery logic for Dockerfiles is a bit limited on 9.9. Indeed, it treats Dockerfile[.*] and [*.]Dockerfile as Dockerfiles. With the later versions (starting with 10.2), you can have a more fine-graned control with the property sonar.docker.file.patterns.

If upgrading SonarQube is not an option for you, the best solution would be either to exclude this specific file from the analysis with a property like sonar.exclusions=**/Dockerfile.cs or to disable the Docker analysis completely. The latter can be done with the property sonar.docker.activate or from the SQ UI.

Best,

Peter