1

Attempting to build a file with MSBuild gives me this warning:

c:\repo\file.cpp(58): warning C4819: The file contains a character that cannot be represented in the current code page (0). Save the file in Unicode format to prevent data loss [C:\repo\proj.vcxproj]

Prior the build command I check the code page (cmd chcp), which tells me current code page is 65001. Setting it to something else has no apparent effect in the build command.

The exact line (58) failing looks like this:

sprintf(Buffer, "%03d\xb0 %02d' %05.2f\" %s", Splitted.Degree, Splitted.Minutes, Splitted.Seconds, Type.c_str());

No special character as far as I can see. I've rewritten the line in insert mode trying to purge possible gremlin characters and analyzed it in notepad++ showing all symbols - nothing! I've also tried saving the file in unicode (powershell "get-content $file | out-file $file"), converting utf-8 with and without BOM from notepad++ - still nothing! And therefore I'm looking into this code page number weirdness thing. Anything else to try is much welcome in comments.

Something that may or may not affect this is MSBuild (and VS) installed and running in a Docker instance (from Windows base OS). Building the same source in a regular Windows environment never experienced this problem.

Question: Why would MSBuild use code page 0 when system code page is something else (e.g. 65001), and how do I fix it?


Edit

I found the offending "character", or rather escape sequence: \xb0. The intent is to print the degree symbol as found in extended ASCII tables. Changing the b into 7 makes the warning go away. From what I understand what it means is code page 0 does not support the extended ascii range.

Still don't get why the build is using code page 0 instead of system though.

Andreas
  • 5,086
  • 3
  • 16
  • 36
  • To me it sounds like it's complaining that a byte is 0 rather than the code page is 0. To my knowledge, there is no code page 0. – Hans Kilian Nov 06 '19 at 13:28
  • @HansKilian Wikipedia claims 0 is reserved by Microsoft (and IBM) for ["Internal OS use"](https://en.wikipedia.org/wiki/Code_page#0). – Andreas Nov 06 '19 at 14:36
  • I didn't know that. I still think the error message sounds like there's a 0 byte in your file though. – Hans Kilian Nov 06 '19 at 14:46
  • @HansKilian Found the "byte", or rather the escape sequence "\xb0". Removing it or changing into 20-7F range silences the error. Still no luck in msbuild code page selection though :( – Andreas Nov 06 '19 at 15:13

0 Answers0