在 .NET 框架中强制使用英语语言异常 [英] Forcing English language exceptions in .NET framework

查看:13
本文介绍了在 .NET 框架中强制使用英语语言异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 ASP.NET MVC 时,我注意到安装在我的系统上的 .NET 框架发出的异常消息是德语的.我真的更喜欢英文信息,所以我可以在 SO 上发布它们.

While working with ASP.NET MVC, I have noticed that exception messages issued by the .NET framework installed on my System are in German. I'd really prefer English messages, so I can post them on SO.

我知道之前有人问过这个问题,但奇怪的是,在我的情况下,建议的解决方法似乎都不起作用.我已经尝试了以下方法:

I know this has been asked before on SO, but strangely enough none of the suggested workarounds seem to work in my case. I have already tried the following:

  • 将我的 Windows 系统切换到英语语言环境并重新启动 Visual Studio
  • 设置工具 -> 选项 -> 环境 -> 国际设置 -> 语言为英语"
  • 在抛出异常之前将线程区域设置为英语,如下所示:

  • switching my Windows system to an English locale and restarting Visual Studio
  • Setting Tools -> Options -> Environment -> International Settings -> Language to "English"
  • setting the thread locale to English right before the exception is thrown as follows:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("zh-CN");Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-US");

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture ("en-US"); Thread.CurrentThread.CurrentUICulture=new CultureInfo("en-US");

//调用我的错误方法...

//call my faulty method...

那么,如何使 .NET 框架发出英语异常消息?是否有任何方法可以在每个解决方案甚至整个系统范围内执行此操作?

So, how can I make the .NET framework issue English language exception messages? And is there any approach that does this on a per-solution or even system-wide basis?

在执行我的单元测试时抛出异常.我不确定这是否是设置线程文化无效的原因.

The exception is thrown while excuting my unit tests. I am not sure if this is the reason setting the thread's culture had not effect.

推荐答案

我刚刚发现,问题确实与测试项目不同.虽然我在实际项目中尝试将 UI 语言设置为英语,但我在测试项目中没有这样做,这就是为什么在查看测试结果时异常消息仍然是德语的原因.

As I just found out, the problem was indeed related to having a different test project. While I have tried setting the UI language to English in my actual project, I did not do the same in the test project, which is why the exception messages were still in German when looking at the test results.

在抛出异常之前在测试方法中设置 UI 语言对我来说是诀窍.

Setting the UI language in the test method right before the exception is thrown did the trick for me.

这篇关于在 .NET 框架中强制使用英语语言异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆