I have a program which reports errors/stack trace back to me in case of crash and if user wishes to send it.
Occasioanly I receive wierd charcters in error message and also stack trace as you can see below.
ファイルã¾ãŸã¯ã‚¢ã‚»ãƒ³ãƒ–リ 'Interop.iTunesLib, Version=1.11.0.0, Culture=neutral, PublicKeyToken=null'ã€ã¾ãŸã¯ãã®ä¾å˜é–¢ä¿‚ã® 1 ã¤ãŒèªã¿è¾¼ã‚ã¾ã›ã‚“ã§ã—ãŸã€‚指定ã•れãŸãƒ•ァイルãŒè¦‹ã¤ã‹ã‚Šã¾ã›ã‚“。
stack trace
------------------------------------------------------
å ´æ‰€ STLib.TInfo.Init(Form f)
å ´æ‰€ STLib.FormMain..ctor() å ´æ‰€ C:\repo_sync\ST\FormMain.cs:行 37
å ´æ‰€ STLib.Program.Main() å ´æ‰€ C:\repo_sync\ST\Program.cs:行 54
My code that builds up the stack trace looks like this
private static void GlobalThreadExceptionHandler(object sender, System.Threading.ThreadExceptionEventArgs e)
{
...
String stackTrace = "";
Exception currentEx = e;
do
{
stackTrace += string.Format("\r\n{0}", currentEx.Message);
stackTrace += "\r\n------------------------------------------------------";
stackTrace += string.Format("\r\n{0}", currentEx.StackTrace);
currentEx = currentEx.InnerException;
if (currentEx != null)
{
stackTrace += "\r\nCaused by";
}
}
while (currentEx != null);
.....
}
I guess probably it has to do Non English language of that machine, can someone please advise me on this as to whats wrong here..
Added after Hans Pasant’s comment
I have following code which converts the stack trace to bytes before posting to a web..
byte[] postdata = System.Text.Encoding.UTF8.GetBytes(stackTrace)
I post this data using exactly the same code as here
Multipart forms from C# client posted by Brian Grinstead
This is a text encoding problem. You’ll get this when your code bombs on a machine that’s for example Japanese, Korean or Chinese. Exception traces are generated using the machine’s default language. The English version looks like:
at namespace.method(args) in C:\path\filename.cs:line 10where the
at,inandlineparts of the message will be in the native language, using character glyphs for CJK languages. Everything will work in the snippet you posted. What goes wrong is what you do to get the string from the crashing machine to your machine. Which is entirely unclear from the question. But if you, say, do it with an email message then you are not using the proper BodyEncoding. Or you do but your email reader doesn’t interpret it correctly.The high incidence of
ãƒmakes it likely that the original text was encoded in utf8, they are character codes 0xC3 and 0x83 when using a Western code page. Which are the first 2 bytes of 3 byte utf-8 sequences for codepoints U+30C0 and up. Which are Hiragana and Katakana glyphs. Thus making it pretty likely that your program crashed on a Japanese machine. And that you read the text with Encoding.Default on your machine instead of Encoding.UTF8