6

I have a couple of files that are not analyzed with the following message:

Invalid character encountered in file [file name with full path] at line 9 for encoding UTF-8. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.

In Visual Studio when I select File / Advance Save Options, the files were set to Western Europe (Windows) - Codepage 1252.

I changed it to Unicode (UTF-8 with Signature) - Codepage 65001.

But SonarQube still complains about the invalid characters. The "invalid characters" are comments in German with Umlaut-characters (ä,ö,ü)

What can I do to fix this (without removing the comments)?

tobre
  • 1,231
  • 2
  • 16
  • 44
  • I also have the same problem after upgrading to SonarQube 5.6.6 - same problem with German umlauts. sonar.sourceEncoding = UTF-8 is set - the ue-umlaut is CEBC in hex editor, so everything should be ok - how did you solve your problem? – outofmind Mar 23 '17 at 10:36
  • I used a script from the following [link] (http://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom). That works well with C#. If you have C++ sources as well, you might need to convert to UTF-8 with BOM. For that I used a Powershell script UTF8-EncodeFilesWithBOM `$basePath = "C:\Main\System" foreach($line in Get-Content "C:\Temp\utf\utfErrors2.txt") { $file = Join-Path -Path $basePath -ChildPath $line (Get-Content $file -Encoding UTF8) | Set-Content -Encoding UTF8 $file }` – tobre Mar 31 '17 at 05:58

2 Answers2

0

The SonarQube Scanner for MSBuild and the SonarQube C# plugin currently expect all files of the project to have the UTF-8 encoding - and this is hardcoded.

There is a ticket to improve this in a future version: https://jira.sonarsource.com/browse/SONARMSBRU-174

Dinesh Bolkensteyn
  • 2,921
  • 1
  • 15
  • 19
  • How come it still did not work after changing the encoding to UTF-8? – tobre Nov 13 '15 at 08:46
  • I suspect that the file's encoding has not been properly changed. You can have a look at line 9 of that file in a hexadecimal editor to see for yourself whether it looks correct or not. – Dinesh Bolkensteyn Nov 13 '15 at 08:50
0

I got the same error Invalid Character encountered in file when XML files were analyzed. And I already had sonar.sourceEncoding=UTF-8 in my properties file.

The problem was I didn't have XML plugin installed in Sonar. Once I installed that via Update Center, this issue for resolved. Hope this helps anyone else facing this issue.

Henry
  • 16,294
  • 7
  • 56
  • 86