There are Problems with file encoding in the source code

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Scanner command used when applicable: scannerMode: ‘dotnet’
  • Languages of the repository: c#, TS, JS, json, xml
  • Projects are private
  • Error observed:

During the SonarQube Cloud Publish, we see:

[INFO] SonarQube Cloud: Analysis succeeded with warning: There are problems with file encoding in the source code. Please check the scanner logs for more details.

We also see this warning inside the SonarQube Cloud portal for the projects.

We think this might cause our projects to be scanned incorrectly, since they no longer have any lines of code.

Where do I find these logs or can you please look them up for us? So we can learn which files it is the scanner cannot read.

Example of the failing IDs:

AZ-N8JNGlNY5YPvmW5fT

AZ-N9i9BiqMlMXE6gQjn

Thank you

Mikkel

I might have found a log statement in the SonarQube Cloud Analysis that tells it cannot parse an ico file, trying to ignore that one now.

It is not a file we have added lately, I am fairly sure the scanner somehow found it back in august and have failed since, but we did not see that this warning appeared and stripped alot of code from our analysis.

Why would you ever let the SonarQube Cloud Publish task complete with success when it is reporting that there is a problem with the analysis?

How can I make it fail?

Thanks

Mikkel

Did not help to set ico files as ignored, please look at this:

From the “SonarQube Cloud Analyze” task:

Excluded sources: **/wwwroot/**/*, **/lcov-report/**/*, **/obj/**, **/bin/**, **/*.ico, **/node_modules/**/*, **/bin/Release/**/*, **/obj/**/*

You can see it has picked up the ignore of ico and I tried multiple for obj folder

Still I see in the logs afterwards:

WARN: Invalid character encountered in file /mnt/vss/_work/1/s/REDACTED/obj/Release/net8.0/apphost at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

WARN: Invalid character encountered in file /mnt/vss/_work/1/s/REDACTED/src/favicon.ico at line 1 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

Why? they are excluded right?

This analysis has Task: AZ-UBWsIFiCT6lNyKKRW

Thanks

Mikkel

Hey @Mikkel, normally excluding should get rid of the warning, yes. Could you share the full debug-level logs? I want to see the context in which these invalid character warnings occur.

Hi,

Can I upload the logs without them being public? There is alot of customer specific in them.

What I can interpretate myself from the logs, the scanner makes the mistake to identify all code as test code. I can see:

GUID.sonar.sources=(empty)

GUID.sonar.tests=\… then all our files

among the test files I see the ico file and also files from the obj/Release folder.

Thank you

Mikkel

Aha, so it sounds like the problem is that your files are being miscategorized as test instead of main code, and sonar.exclusions (Excluded sources: ...) applies only to main code. So the correct exclusion property would be sonar.test.exclusions.

However, what you should do is not to switch to sonar.test.exclusions, but to fix the miscategorization of main code as test. In .NET, this sometimes happens because certain dependencies implictly signal that a project is a test project instead of main. You can read more about it here. You should look for logs (debug level) evidencing the categorization of projects as test. The simplest fix is to just explicitly mark it as non-test.

This seems like the same problem I’ve reported here: "WARN: Invalid character encountered" for binary files since 2026-07-02

Thank you, I found the nuget package which had the xunit reference by running the dotnet build with -v diag.

For the question if it is possible to detect warnings during the SonarQube Cloud Publish task, is there any recommendations? I would really not let a PR continue with warnings, since it can invalidate the Quality Gate completly if all code suddenly is marked as Test code.

thanks

It’s not really possible out of the box in the Publish task, although you could write your own check in the Azure pipeline. If you want to prevent the possibility of this happening, your best bet is to explicitly categorize the projects as test or non-test.