visual-studio 强制例外语言为英语
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2092298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force exceptions language in English
提问by serhio
My Visual Studio 2005is a French one, installed on a French OS. All the exceptions I receive during debug or runtime I obtain also in French.
我的 Visual Studio 2005是法语版,安装在法语操作系统上。我在调试或运行时收到的所有异常也是用法语获得的。
Can I however do something that the exceptions messages be in English? For goggling, discussing etc.
但是,我可以做一些例外消息是英文的吗?用于护目镜、讨论等。
I tried the following:
我尝试了以下方法:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
throw new NullReferenceException();
obtained
获得
Object reference not set to an instance of an object.
你调用的对象是空的。
This is, surely, cool... but, as I work on a French project, I will not hardcode forcing Thread.CurrentUICulture to English. I want the English change to be only on my local machine, and don't change the project properties.
这当然很酷……但是,当我在一个法语项目中工作时,我不会将 Thread.CurrentUICulture 硬编码为英语。我希望英语更改仅在我的本地机器上进行,并且不要更改项目属性。
Is it possible to set the exceptions language without modifying the codeof the application?
是否可以在不修改应用程序代码的情况下设置异常语言?
In VS 2008, set the Tools -> Options -> Environment -> International Settings -> Language to "English" wnd throwing the same exception obtain the ex message en French, however: alt text http://lh4.ggpht.com/_1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png
在 VS 2008 中,将工具 -> 选项 -> 环境 -> 国际设置 -> 语言设置为“英语” wnd 抛出相同的异常获取法语消息,但是: alt text http://lh4.ggpht.com/ _1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png
采纳答案by serhio
Finally a "sharp" solution could be the following:
最后一个“敏锐”的解决方案可能如下:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#if DEBUG
// Add this; Change the Locales(En-US): Done.
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
#endif
Application.Run(new Form1());
}
However I'd like a solution without modifications in the project code.
但是我想要一个无需修改项目代码的解决方案。
From MSDN:
从MSDN:
The CurrentUICultureproperty will be set implicitly if an application does specify a CurrentUICulture. If CurrentUICultureis not set explicitly in an application's code, it is set by the GetUserDefaultUILanguagefunction on Windows 2000 and Windows XP Multilingual User Interface (MUI) products where the end user can set the default language. If the user's UI language is not set, it will be set by the system-installed language, which is the language of the operating system's resources.
If an application is Web-based, the CurrentUICulturecan be set explicitly in application code to the user's browser accept language.
该的CurrentUICulture属性将被隐式设置如果应用程序不指定的CurrentUICulture。如果 CurrentUICulture未在应用程序代码中明确设置,则由Windows 2000 和 Windows XP 多语言用户界面 (MUI) 产品上的GetUserDefaultUILanguage函数设置,最终用户可以在其中设置默认语言。如果未设置用户的 UI 语言,则将由系统安装的语言设置,即操作系统资源的语言。
如果应用程序是基于 Web 的,则可以在应用程序代码中将 CurrentUICulture显式设置为用户浏览器接受的语言。
回答by Thomas Levesque
You could set the current culture to English only in debug builds :
您只能在调试版本中将当前文化设置为英语:
#if DEBUG
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
回答by Stanislav Berkov
This is known problem. Please vote for fix here: https://connect.microsoft.com/VisualStudio/feedback/details/591839/exception-localization-in-app-config-and-web-config
这是已知问题。请在这里投票修复:https: //connect.microsoft.com/VisualStudio/feedback/details/591839/exception-localization-in-app-config-and-web-config
回答by IllidanS4 wants Monica back
For the good of all future users of your application, place this to the Mainmethod:
为了您的应用程序的所有未来用户的利益,请将其放在Main方法中:
CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
It will save them a good lot of trouble finding the English equivalent of a a badly translated error message.
它将为他们省去很多麻烦,找到与翻译得不好的错误消息等效的英文。
回答by tomsv
Uninstall the French language pack:
卸载法语语言包:
Start - Control Panel - Programs and Functions - Microsoft .NET Framework (4 Client Profile) Language Pack FRU - Uninstall
开始 - 控制面板 - 程序和功能 - Microsoft .NET Framework(4 客户端配置文件)语言包 FRU - 卸载
You may need to repeat the uninstallation for each version of .NET Framework that you find there.
您可能需要为在那里找到的每个 .NET Framework 版本重复卸载。
回答by KuN
For any Win8/8.1 users facing this issue, installing the English Language Pack and make it the Windows display languageseems to be only easy way to resolve it as Win8 has .net framework built in its core.
对于任何面临此问题的 Win8/8.1 用户,安装英语语言包并使其成为Windows 显示语言似乎是解决此问题的唯一简单方法,因为 Win8 的核心内置了 .net 框架。
Probably the same for Win10.
Win10大概也是这样。
回答by Matteo Italia
I didn't try, but according to the documentationthat property should be set by default to the current UI language, that is set in the control panel. So it should work correctly automagically according to your international settings.
我没有尝试,但根据文档,该属性应默认设置为当前的 UI 语言,即在控制面板中设置的。所以它应该根据您的国际设置自动正常工作。

