問題描述
在使用 ASP.NET MVC 時(shí),我注意到安裝在我的系統(tǒng)上的 .NET 框架發(fā)出的異常消息是德語的.我真的更喜歡英文信息,所以我可以在 SO 上發(fā)布它們.
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.
我知道之前有人問過這個(gè)問題,但奇怪的是,在我的情況下,建議的解決方法似乎都不起作用.我已經(jīng)嘗試了以下方法:
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 系統(tǒng)切換到英語語言環(huán)境并重新啟動(dòng) Visual Studio
- 設(shè)置工具 -> 選項(xiàng) -> 環(huán)境 -> 國際設(shè)置 -> 語言為英語"
在拋出異常之前將線程區(qū)域設(shè)置為英語,如下所示:
- 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");
//調(diào)用我的錯(cuò)誤方法...
//call my faulty method...
那么,如何使 .NET 框架發(fā)出英語異常消息?是否有任何方法可以在每個(gè)解決方案甚至整個(gè)系統(tǒng)范圍內(nèi)執(zhí)行此操作?
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?
在執(zhí)行我的單元測(cè)試時(shí)拋出異常.我不確定這是否是設(shè)置線程文化無效的原因.
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.
推薦答案
我剛剛發(fā)現(xiàn),問題確實(shí)與測(cè)試項(xiàng)目不同.雖然我在實(shí)際項(xiàng)目中嘗試將 UI 語言設(shè)置為英語,但我在測(cè)試項(xiàng)目中沒有這樣做,這就是為什么在查看測(cè)試結(jié)果時(shí)異常消息仍然是德語的原因.
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.
在拋出異常之前在測(cè)試方法中設(shè)置 UI 語言對(duì)我來說是訣竅.
Setting the UI language in the test method right before the exception is thrown did the trick for me.
這篇關(guān)于在 .NET 框架中強(qiáng)制使用英語語言異常的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!