为什么 "new CultureInfo("xx")" 在一个环境中抛出异常,而在另一个环境中不抛出异常?
Why does "new CultureInfo("xx")" throw an exception in one environment but not in another?
我的 Asp.Net MVC 应用程序以 .Net Framework 4.6.1 为目标
在我的开发环境中,这有效:
var x = new CultureInfo("xx")
版本信息:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4210.0
(我从同一个 MVC 应用程序的其他地方的随机错误页面获得此信息,在底部提到)
IIS 10.0.18362.650 Windows 10 build 18363.1016
(从 IIS 管理器获得的信息 - 帮助 - 关于)
在托管的暂存(和实时)环境中,相同的代码会引发异常
[CultureNotFoundException: Culture is not supported.
Parameter name: name
xx is an invalid culture identifier.]
System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) +230
版本信息:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3928.0
Windows Server 2012 R2
上的 IIS 8.5.9600.16384
我知道“xx”不是有效的区域性(我只是用它来比较不同语言的资源文件,并且需要一个不存在的区域性)。但我想知道的是为什么这在一个环境中失败而在另一个环境中起作用。 asp.net 版本(几乎)相同。
What is happen is when you create a culture with name like "aaa" which
is is not one of the names carried by Windows, at that time Windows
will try to create it for us and try to fill the culture properties as
much it can by matching the language part and country part. for
example, if I try to create ja-US which I think not exist, Windows
will try to fake the culture by getting the language information from
the Japanese language and will get the country information from US and
combine it into a new culture. now when passing "aaa" which not
matching any language/country, Windows will just use Invariant culture
properties for that. And that is what you are seeing.
This is the behavior defined by Windows starting Windows 10 and not
really the .NET. the framework just calling the OS for getting the
needed information. the code of CreateSpecificCulture is just calling
the OS at the end.
我的 Asp.Net MVC 应用程序以 .Net Framework 4.6.1 为目标
在我的开发环境中,这有效:
var x = new CultureInfo("xx")
版本信息:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4210.0 (我从同一个 MVC 应用程序的其他地方的随机错误页面获得此信息,在底部提到)
IIS 10.0.18362.650 Windows 10 build 18363.1016 (从 IIS 管理器获得的信息 - 帮助 - 关于)
在托管的暂存(和实时)环境中,相同的代码会引发异常
[CultureNotFoundException: Culture is not supported.
Parameter name: name
xx is an invalid culture identifier.]
System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride) +230
版本信息:Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3928.0 Windows Server 2012 R2
上的 IIS 8.5.9600.16384我知道“xx”不是有效的区域性(我只是用它来比较不同语言的资源文件,并且需要一个不存在的区域性)。但我想知道的是为什么这在一个环境中失败而在另一个环境中起作用。 asp.net 版本(几乎)相同。
What is happen is when you create a culture with name like "aaa" which is is not one of the names carried by Windows, at that time Windows will try to create it for us and try to fill the culture properties as much it can by matching the language part and country part. for example, if I try to create ja-US which I think not exist, Windows will try to fake the culture by getting the language information from the Japanese language and will get the country information from US and combine it into a new culture. now when passing "aaa" which not matching any language/country, Windows will just use Invariant culture properties for that. And that is what you are seeing.
This is the behavior defined by Windows starting Windows 10 and not really the .NET. the framework just calling the OS for getting the needed information. the code of CreateSpecificCulture is just calling the OS at the end.