为什么会显示“不支持文化”?以及我应该怎么做? [英] Why do I get, "Culture is not supported" and What, if Anything, Should I Do about it?

查看:341
本文介绍了为什么会显示“不支持文化”?以及我应该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的返回行上有一个断点:

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,

异常:抛出:不支持文化。(System.Globalization.CultureNotFoundException)
抛出了System.Globalization.CultureNotFoundException :不支持文化。

试图支持哪种文化,为什么不支持这种文化,我应该怎么办?是否支持文化?

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

向sphanley的答案:

Answer to sphanley:

除了代表 BarbeQue的新骑手之外,它还是一个骨架(目前),看起来像这样:

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



回答AnotherUser:

UPDATE 2

Answer to AnotherUser:

这不是我的代码,所以我只是在尝试使用它;它提供了一个起点,让我可以复制/重构现有的独立项目,并将其合并到 the解决方案中。话虽如此,回答您的问题,这里是解决方案中 GetTestMessage()的所有实例:

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);
    }
}


推荐答案


正在尝试支持哪种文化

Which culture is trying to be supported

在有问题的地方进行尝试/捕获并捕获异常。在catch块内放置一个断点并调试代码。检查抛出的 CultureNotFoundException InvalidCultureName 属性。这会告诉您正在尝试使用哪种文化,但在系统上找不到。

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具有一组内置的Cultures(。NET 3.5中的CultureInfo类支持哪些文化? http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx )。如果 InvalidCultureName 中列出的区域性不在列表中,则不支持。

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?

这取决于 InvalidCultureName code>是。如果您合法地尝试使用不受支持的文化(例如,您有一个多语言/多区域站点,并且希望为每种文化提供英语支持),则可能有必要创建一种新的文化。例如,我在一个网站 http://www.oneill.com 上工作,荷兰网站的法语版本( http://www.oneill.com/nl-fr)。我们必须创建一种新的区域性,并使用以下说明将其安装在Web服务器上: http://msdn.microsoft.com/zh-cn/library/ms172469(v = vs.90).aspx

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

如果您没有做任何花哨的文化工作,则asp.net存在一些已知问题,该问题涉及框架错误地针对基于目录的目录错误地创建了 CultureInfo 实例当前:

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

在这种情况下,看起来像s解决方法是关闭异常并忽略它。

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

这篇关于为什么会显示“不支持文化”?以及我应该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆