Jefraim
Jefraim

Reputation: 193

Japanese string literals & Visual Studio 2010 & error CS1009: Unrecognized escape sequence

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.

Upvotes: 0

Views: 1104

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100545

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.

Upvotes: 2

Related Questions