0
votes

I have a visual studio project that contains Japanese string literals. This project can be built completely fine in a Japanese system (Japanese Windows XP) and an English Visual Studio 2010 IDE.

But if I build the project in an English system (English Windows XP) and English Visual Studio 2010 IDE, I get a lot of "error CS1009: Unrecognized escape sequence" errors.

What can be the possible cause of this? Can we configure Visual Studio 2010 to interpret the project as UTF8 based?

I looked everywhere and can't seem to find a solution.

Sample code:

try
{
    //ƒRƒ“ƒo[ƒg‘Îۂ̃tƒ@ƒCƒ‹ƒŠƒXƒg•\ަDlgŒÄ‚Ño‚µ&ˆ—ŽÀs
    frmSelFiles = new frmSelectFile(strLoadPath, strSavePath);
    frmSelFiles.ShowDialog(this);
}
catch(ConvertException ce)
{
    throw ce;
}
catch(Exception e2)
{
    // the gibberish strings are actually Unicode characters
    // the CSC1009 error occurs here: \Ž
    ConvertException ce = new ConvertException(e2,"ƒtƒ@ƒCƒ‹‘I‘ðƒ_ƒCƒAƒƒOƒ{ƒbƒNƒX‚ð•\ަ‚Å‚«‚Ü‚¹‚ñB");
    throw ce;
}
finally
{
    //ƒŠƒ\[ƒX‰ð•ú
    if(frmSelFiles != null)
    {
        frmSelFiles.Dispose();
    }
}

The solution:

I was able to resolve this by changing the default locale setting of the environment. For WinXP's case, we probably need to set the "Language for Non-Unicode Programs". In Win Server 2008 R2, I changed the default System locale.

It appears that MSBuild or MS Visual Studio (2010) takes the "Language for Non-Unicode Programs" setting.

1
Can you post some code where this error has occurred...?? - Hiren Pandya
Have you tried with this... <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="nb-no" uiCulture="no"/> - Hiren Pandya
If it is small project resaving all CS files with "UTF8 with BOM" encoding may be the easiest approach. - Alexei Levenkov
Thanks for the response Hiren. Where do we set that configuration? - Jefraim
Alexei, it can't be. The project has lots of files. I'm thinking that it can be fixed by configuration because it works fine in an English VS2010 and JA Windows XP. - Jefraim

1 Answers

2
votes

It looks like you have files saved in default Japanese encoding and as result they work fine when locale (or maybe "non-Unicode locale") set to matching encoding.

To my knowledge there is no way to configure C# compiler and VS to open such files in non default encoding.

You options:

  • configure all machines where project is going to be open to use the same locale/language as you JA-JP Win XP
  • resave all files with one of Unicode encoding (Unicode or Utf8 with BOM). One should be able to write small script/C# program to open files with correct encoding and save in UTF8 if there are many files.
  • Remove all non-ASCII strings from code and move them to resources.