问题描述
我在此处的返回"行上有一个断点:
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:
除了代表New Riders of the 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; }
}
更新 2
回答另一个用户:
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;
}
...还有这个测试:
[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);
}
}
推荐答案
在违规行周围放置一个 try/catch 并捕获异常.在 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.
为什么不支持
Windows 有一组内置的文化 (.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.
如果有的话,我应该做些什么来支持这种文化?
这取决于 InvalidCultureName
是什么.如果您合法地尝试使用不受支持的文化(例如,您有一个多语言/多区域站点并希望为每种文化支持英语),您可能有创建新文化的合理需求.例如,我在一个网站 http://www.oneill.com 上工作,我们希望在那里拥有荷兰网站的法语版 (http://www.oneill.com/nl-fr).我们必须创建一种新的文化并使用以下说明将其安装在 Web 服务器上:http://msdn.microsoft.com/en-us/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
在这种情况下,看起来解决方案是关闭异常并忽略它.
In that case, looks like the solution is to just turn off the Exception and ignore it.
这篇关于为什么我得到,“不支持文化"如果有的话,我应该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!