Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
    }
}
like image 255
B. Clay Shannon-B. Crow Raven Avatar asked Jun 20 '14 17:06

B. Clay Shannon-B. Crow Raven


2 Answers

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.

like image 113
Koby Douek Avatar answered Nov 15 '22 23:11

Koby Douek


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.

like image 24
Philip Pittle Avatar answered Nov 15 '22 21:11

Philip Pittle