Why do I get, "Culture is not supported" and What, if Anything, Should I Do about it?
Asked Answered
L

2

13

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

[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
    return NRBQClient.GetTestMessage(id1, id2);
}

Although it does not crash the app, when I reach that point, I get,

"Exception:Thrown: "Culture is not supported." (System.Globalization.CultureNotFoundException) A System.Globalization.CultureNotFoundException was thrown: "Culture is not supported.""

Which culture is trying to be supported, why is it not supported, and what, if anything, should I do to support the culture?

UPDATE

Answer to sphanley:

Besides standing for "New Riders of the BarbeQue," it is a "skeleton" (for now) Entity that looks like this:

public class NRBQEntity
{
    public NRBQEntity()
    {

    }

    public String Value { get; set; }
}

UPDATE 2

Answer to AnotherUser:

This is not my code, so I'm just in the process of trying to grok it; it has been provided as a starting point for me to copy over/refactor an existing standalone project, incorporating it into "the" solution. That having been said, to answer your question, here are all the instances of "GetTestMessage()" in the solution:

[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
    return NRBQClient.GetTestMessage(id1, id2); 
}

[HttpGet]
[Route("api/Test/{id1}/{id2}")]
public NRBQEntity GetTestMessage(String id1, String id2)
{
    return NRBQService.GetNRBQEntity(id1, id2);
}

public interface INRBQClient
{
    NRBQEntity GetTestMessage(String id1, String id2);
}

public NRBQEntity GetTestMessage(String id1, String id2)
{
    var res = RESTAPIClient.GET<NRBQEntity>(null
       , new Uri(NRBQClientSettings.NRBQAPI)
       , String.Format("api/Test/{0}/{1}"
                        , id1
                        , id2)
                        );

    if (res.status != RequestResultStatus.Success)
    {
        throw new Exception(res.message);
    }

    return res.result;
}

...and this test:

[TestFixture, Category(DRBCOMMON.UnitTests.Categories.IntegrationTest)]
public class NRBQClientIntegrationTests
{    

    [Test]
    public void TestNRBQInterface()
    {
        var NRBQClient = IOC.container.Resolve<INRBQClient>();

        var s = NRBQClient.GetTestMessage("GET", "SORTY");

        Assert.Greater(s.Value.Length, 0);
    }
}
Legation answered 20/6, 2014 at 17:4 Comment(7)
Do you/we know what GetTestMessage looks like?Bullins
googling it brings more complains about it and root cause may be a bug in System.Web - resolution may be to install updates for your visual studio and .net framework. For example: #2117321 However in your particular case it may also be a bug in your custom code so that invalid culture name is passed to CultureInfo constructor one way or another. So additional stack trace could help. As well as full message. So that based on it's value it would be easier to guess.Sower
you do not give us enought to diagnose the problem!Treenware
@giammin: To quote my old high school P.E. coach, "Whaddaya want - egg in your beer?!?"Legation
@B.ClayShannon i want a stack trace and the exact line that throws the exceptionTreenware
@giammin: It has not happened again, so I don't know what caused it, or what caused it to go away.Legation
Put the breakpoint and see what culture you running. If it is not en-us, before return set it on the thread to en-us. See what happensAdvisable
S
5

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:

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

Savell answered 18/7, 2014 at 8:29 Comment(0)
P
2

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.

Prothesis answered 28/3, 2017 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.