【问题标题】:System.Globalization.CultureInfo.GetCultures returning null in dev environment (Visual Studio)System.Globalization.CultureInfo.GetCultures 在开发环境中返回 null (Visual Studio)
【发布时间】:2016-11-21 14:29:59
【问题描述】:

首先,这很可能是我的新手错误,我对 .net 和 c# 还很陌生。

我在我们最新的项目中使用 CMS 系统 Umbraco,最近的更新意味着该系统已开始使用 System.Globalization.CultureInfo 类来处理本地化。这导致 CMS 后台出现多个“未找到文化”错误,使其无法使用。这是其中一个的堆栈跟踪:

Server Error in '/' Application.

Culture is not supported.
Parameter name: name
.-no is an invalid culture identifier.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Globalization.CultureNotFoundException: Culture is not supported.
Parameter name: name
.-no is an invalid culture identifier.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[CultureNotFoundException: Culture is not supported.
Parameter name: name
.-no is an invalid culture identifier.]
   System.Globalization.CultureInfo.GetCultureInfo(String name) +12488971
   Umbraco.Core.Services.LocalizedTextServiceFileSources.<.ctor>b__0() +573
   System.Lazy`1.CreateValue() +180
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +26
   System.Lazy`1.get_Value() +12446617
   Umbraco.Core.Services.LocalizedTextServiceFileSources.TryConvert2LetterCultureTo4Letter(String twoLetterCulture) +61
   Umbraco.Core.Services.LocalizedTextService.ConvertToSupportedCultureWithRegionCode(CultureInfo currentCulture) +110
   Umbraco.Core.Services.LocalizedTextService.GetAllStoredValues(CultureInfo culture) +72
   Umbraco.Web.Editors.BackOfficeController.LocalizedText(String culture) +123
   lambda_method(Closure , ControllerBase , Object[] ) +77
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9765121
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

我仍然不完全确定 .-no 来自哪里,但经过一些研究后,我尝试运行以下代码并插入断点:

var locale = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);

这返回了 null,并且似乎没有在任何地方抛出异常。从堆栈跟踪来看,我猜这可能是错误的原因。这可能是我的本地设置的问题吗?我正在运行 Windows 10,主要是在虚拟化环境中,但它也可以通过 OSX Bootcamp 本地运行,问题似乎仍然存在。我也尝试过使用 Powershell 输出已安装的文化列表,效果很好。

如果有帮助,我将 IISExpress 用于 Web 服务器,并且数据库在 SQL Server 2016 Express 下运行。

提前致谢!如果我可以提供任何额外信息来帮助解决这个问题,请告诉我。

【问题讨论】:

    标签: c# asp.net umbraco umbraco7


    【解决方案1】:

    利用 Umbraco 是开源的这一事实。

    从您提供的堆栈跟踪和异常详细信息来看,问题是由这行引起的:

    https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Core/Services/LocalizedTextServiceFileSources.cs#L102

    显然无效值 .-no 被传递到 GetCultureInfo 方法。如果你在源代码中查找一下,似乎这个值来自 XML 文件名或 XML 文件内容。

    我无法为您的问题提供完整的解决方案,但这里有一些事情可以尝试找出问题的根本原因:

    1) 清理部署文件夹

    执行完整的清理和重建周期

    2) 检查本地化 XML 文件以检查它们是否包含有效的文化

    如果您手动编辑过文件,请确保那里没有错字。

    3) 比较“全新”安装文件夹和非工作解决方案文件夹

    检查更新是否没有留下以前版本的一些 XML 文件;

    【讨论】:

    • 感谢您的及时答复。我已经尝试运行一些 Umbraco 方法,进一步回溯跟踪,在查询相关 XML 文件时,它似乎默认为“en”文化。有点奇怪的是,我的开发环境中的 System.Globalization.CultureInfo.GetCultureInfo("en") 或 "en-US" / "en-GB" 返回 null。有什么理由会这样吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 2018-03-03
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    相关资源
    最近更新 更多