Why do I get, “Culture is not supported” and What, if Anything, Should I Do about it?

前端 未结 2 1149
感动是毒
感动是毒 2020-12-18 23:31

I have a breakpoint on the \"return\" line here:

[HttpGet]
[Route(\"api/Test/{id1}/{id2}\")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
    r         


        
相关标签:
2条回答
  • 2020-12-19 00:09

    You can check all existing codes in this list.

    You can create a custom culture, like so:

    // Create a new colture, with the name you desire
    CultureAndRegionInfoBuilder cib = new CultureAndRegionInfoBuilder("en-IN", CultureAndRegionModifiers.None);
    
    // Load all defaults from en-US
    CultureInfo ci = new CultureInfo("en-US");
    cib.LoadDataFromCultureInfo(ci);
    
    // Populate the new CultureAndRegionInfoBuilder object with region information.
    RegionInfo ri = new RegionInfo("US");
    cib.LoadDataFromRegionInfo(ri);
    
    // Now you can make changes, or finish.
    // Changes can be currency, RegionName, etc.
    
    // Finish
    cib.Register();
    

    this article explains how to do it.

    0 讨论(0)
  • 2020-12-19 00:22

    Which culture is trying to be supported

    Place a try / catch around the offending line and catch the exception. Place a break point inside the catch block and debug your code. Examine the thrown CultureNotFoundException's InvalidCultureName property. This will tell you which Culture is trying be used but is not found on the system.

    Why is it not supported

    Windows has a built in set of Cultures (What cultures are supported by the CultureInfo class in .NET 3.5? and http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx). If the Culture listed in InvalidCultureName is not on the list, it's not supported.

    What, if anything, should I do to support the culture?

    This depends on what InvalidCultureName is. If you are legitimately trying to use a non-supported culture (for example, you have a multi lingual / multi regional site and want to support English for every culture) you may have legitimate need to create a new culture. For example, I worked on a site, http://www.oneill.com, where we wanted to have a French version of the Netherlands site (http://www.oneill.com/nl-fr). We had to create a new culture and install it on the web server using these instructions: http://msdn.microsoft.com/en-us/library/ms172469(v=vs.90).aspx

    If you aren't doing any fancy culture stuff, there are some known issues with asp.net involving the framework erroneously creating CultureInfo instances against based on directories that might not be present:

    • http://edd.stefancamilleri.com/2013/11/25/asp-net-mvc-always-throws-a-system-globalization-culturenotfoundexception/
    • .NET 4.0 - CultureNotFoundException

    In that case, looks like the solution is to just turn off the Exception and ignore it.

    0 讨论(0)
提交回复
热议问题