Azure Web 应用突然不再支持文化

Culture is suddenly not supported anymore on Azure web app(Azure Web 应用突然不再支持文化)
本文介绍了Azure Web 应用突然不再支持文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Out of the blue our Azure web app is spewing out errors regarding a Culture that is not supported. We load up a list of countries to show on the front page but this is suddenly giving errors. The same code is used on other various web apps as well and they aren't having the problem.

The following code gives a problem.

 private List<SelectListItem> Countries()
        {
            RegionInfo country = new RegionInfo(new CultureInfo("nl-BE", false).LCID);
            List<SelectListItem> countryNames = new List<SelectListItem>();
        foreach (CultureInfo cul in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
        {
            country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);
            countryNames.Add(new SelectListItem() { Text = country.DisplayName, Value = country.DisplayName });
        }

        return countryNames.GroupBy(x => x.Text).Select(x => x.FirstOrDefault()).ToList<SelectListItem>().OrderBy(x => x.Text).ToList();
    }

I placed a try-catch in the for-each so I can pinpoint the cultures that are giving errors. The following cultures are suddenly returning errors:

<errors>
<LCID>4096</LCID>
<Name>ar-001</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>el-CY</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-BB</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-BS</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-HK</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-NL</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>en-SE</Name>
</errors>
<errors>
<LCID>4096</LCID>
<Name>es-419</Name>
</errors>

Can someone help me with this issue? I can't seem to make sense on why this web app is suddenly giving these errors.

解决方案

Almost all of the new locales in Windows are not assigned explicit LCIDs - because there is not enough "room" for the thousands of languages in hundreds of countries problem. They all get assigned 0x1000.

In this case, I think a changing LCID to name might work for you:

country = new RegionInfo(new CultureInfo(cul.Name, false).LCID);

to just use the culture name:

country = new RegionInfo(cul.Name);

Of course, any other use of LCID would also need to recognize the culture name instead.

We actually recommend that RegionInfo be constructed with a full culture name since that is more explicit than just the region name.  RegionInfo has some properties that "depend" on the languages, such as the DisplayName. es-US and en-US provide Spanish or English strings for "United States", for example.

Hope that helps,

-Shawn

这篇关于Azure Web 应用突然不再支持文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)