11

On Windows 8 using Visual Studio 2012 RC on a german system, I get all my Exceptions localized to german, which effectively means I can't google anything useful for them. To solve this, I already used the following to change my IDE to english language:

Tools --> Options --> Internetional Settings --> Language --> English

Nevertheless, I get my exceptions in the localized german language. I tried changing the ThreadUI Culture in code using this code:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

Sadly, in WinRT the Thread namespace is gone in WinRT. Therefore I tried:

System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-us");

I get the german exception message still. Does anyone know how to get the un-localized version of the exception messages?

user7116
  • 63,008
  • 17
  • 141
  • 172
Akku
  • 4,373
  • 4
  • 48
  • 67
  • 1
    I'll work in this system for at least two months, and I really don't want to Google Translate everything I google. – Akku Nov 21 '12 at 12:55
  • have you seen this: http://stackoverflow.com/questions/209133/c-sharp-exception-messages-in-english. unlocalize.com looks useful – mcalex Nov 21 '12 at 12:58
  • Doesn't work, as I already wrote, "new System.Threading.Thread" isn't possible as that doesn't exist anymore in WinRT. – Akku Nov 21 '12 at 13:05
  • Ah yes, unlocalize.com could help me for this one issue, but it's the same thing as using Google translate basically. I don't want to go to another website and translate everything, I just want the original message that's in there _somewhere_. – Akku Nov 21 '12 at 13:09
  • Oh and btw. of course you can set your Windows installation to be english, but please just assume I won't or cannot do that. – Akku Nov 21 '12 at 13:25
  • yeah, figured that wasn't an option. It would've been too easy – mcalex Nov 21 '12 at 13:31
  • http://connect.microsoft.com/VisualStudio/feedback/details/760126/windows-8-net-4-5-unable-to-change-frameworks-exceptions-language – Juan Zamudio Dec 04 '12 at 17:49
  • Uninstalling to local .NET language pack solved the issue for me: http://stackoverflow.com/a/23341306/2546759 – Nir Mar 07 '15 at 20:21

2 Answers2

2

Your other option is to retrieve and display the Exception.HResult value, which can be searched upon and turned into a useful error message in English.

Another possibility, if these exceptions have Win32 codes, albeit a hack:

[DllImport("kernel32.dll",
           EntryPoint = "FormatMessageW",
           SetLastError = true,
           CharSet = CharSet.Auto)]
private static extern int FormatMessage(
    int dwFlags,
    IntPtr lpSource,
    int dwMessageId,
    int dwLanguageId,
    StringBuilder lpBuffer,
    int nSize,
    IntPtr[] Arguments);

// used like:
var builder = new StringBuilder(2048);
var res = FormatMessage(
    0x1000|0x0200/*System Message, Ignore Inserts*/,
    IntPtr.Zero,
    exception.HResult,
    new CultureInfo("en-US").LCID,
    builder,
    builder.Capacity,
    null);
 Console.WriteLine("{0}", builder.ToString());
 // throw new StackOverflowException()
 // "Recursion too deep; the stack overflowed."
user7116
  • 63,008
  • 17
  • 141
  • 172
  • Not usable always, e.g. **HttpException** (en: _The file does not exist._, de: _Die Datei URL ist nicht vorhanden._). But HRESULT is **0x80004005** which translates into meaningless _Unspecified error_ message. – tibx May 25 '20 at 15:35
-5

Exceptions have localized messages by design, it's desired behavior. You should change your local computer settings.

kamiloo
  • 15
  • 1
  • 1
    This would be a better answer if you explained how he could go about doing this, and also perhaps about why the IDE settings only effect the IDE itself and not programs which have been compiled with, and run from, the IDE. – TomH Nov 21 '12 at 14:06
  • ... and if the OP said he won't or can't do this. – mcalex Nov 21 '12 at 14:10
  • 3
    Well, the messages are there, the problem is there, and a programatic solution is available for .NET 4 and lower in spite of the questionable design of exceptions (via changing thread locale), so I cannot see why there shouldn't be a solution for .NET 4.5. This answer is lazy and not suitable to my question. – Akku Nov 22 '12 at 08:04