简体   繁体   English

System.Globalization.CultureInfo.GetCultures在开发环境中返回null(Visual Studio)

[英]System.Globalization.CultureInfo.GetCultures returning null in dev environment (Visual Studio)

First of all, this could very well be a rookie mistake on my part, I'm fairly new to .net and c#. 首先,这对我来说很可能是一个新手的错误,我对.net和c#很新。

I'm using the CMS system Umbraco on our latest project, and a recent update has meant the system has started using the System.Globalization.CultureInfo class to deal with localization. 我在我们的最新项目中使用CMS系统Umbraco,最近的更新意味着系统已经开始使用System.Globalization.CultureInfo类来处理本地化。 This has resulted in multiple "Culture Not Found" errors in the CMS back office that renders it unusable. 这导致CMS后台中出现多个“未找到文化”错误,导致其无法使用。 Here's a stack trace from one of them: 这是其中一个的堆栈跟踪:

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

I'm still not completely sure where the .-no is coming from, but after some amount of research into this I tried running the following code with a breakpoint inserted: 我仍然不完全确定。-no来自哪里,但经过一些研究后我尝试运行以下代码并插入断点:

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

This returned null, and doesn't seem to be throwing an exception anywhere. 这返回null,似乎没有在任何地方抛出异常。 I'm guessing this might be the cause of the errors, judging by the stack trace. 我猜这可能是错误的原因,从堆栈跟踪判断。 Could this be an issue with my local setup? 这可能是我本地设置的问题吗? I'm running Windows 10, mainly in a virtualization environment, but it can also run natively via OSX Bootcamp, where the problem still seems to be present. 我正在运行Windows 10,主要是在虚拟化环境中,但它也可以通过OSX Bootcamp本地运行,问题似乎仍然存在。 I've also tried using Powershell to output the list of installed cultures, and that works fine. 我也尝试使用Powershell输出已安装的文化列表,这样可以正常工作。

If it helps, I'm using IISExpress for the web server and the database is running under SQL Server 2016 Express. 如果有帮助,我使用IISExpress作为Web服务器,数据库在SQL Server 2016 Express下运行。

Thanks in advance! 提前致谢! Let me know if I can supply any extra info to help out with this. 如果我能提供任何额外的信息来帮助我,请告诉我。

Make use of the fact that Umbraco is open source. 利用Umbraco是开源的这一事实。

Judging from the stack trace and exception details you have provided, problem is caused by this line: 从您提供的堆栈跟踪和异常详细信息判断,问题是由此行引起的:

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

Apparently invalid value .-no is passed into GetCultureInfo method. 显然无效的值.-no传递给GetCultureInfo方法。 If you look a bit up in the source code, it seems that this value comes from XML file name or XML file content. 如果您在源代码中看起来有点像,那么这个值似乎来自XML文件名或XML文件内容。

I cannot provide complete solution for your problem, but here are some things to try to pinpoint root cause of it: 我无法为您的问题提供完整的解决方案,但是有些事情要尝试找出它的根本原因:

1) Clean deployment folder 1)清理部署文件夹

Do full clean & rebuild cycle 做完全清洁和重建周期

2) Check localization XML files to check if they contain valid cultures 2)检查本地化XML文件以检查它们是否包含有效的文化

If you have edited files manually, make sure there is no typo there. 如果您手动编辑了文件,请确保没有拼写错误。

3) Compare folders of "fresh" install and your non-working solution folder 3)比较“新鲜”安装文件夹和非工作解决方案文件夹

Check if update hasn't left behind some XML files from previous versions; 检查更新是否未遗留以前版本的某些XML文件;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Globalization CultureInfo CultureNotFoundException - System.Globalization CultureInfo CultureNotFoundException UWP与WPF:System.Globalization CultureInfo不同吗? - UWP vs WPF: System.Globalization CultureInfo is different? 有没有办法“尝试解析”一个字符串到 System.Globalization.CultureInfo - Is there a way to “try parse” a string to System.Globalization.CultureInfo 使用System.Globalization.CultureInfo.InvariantCulture进行字符串到日期时间的转换 - string to datetime conversion using System.Globalization.CultureInfo.InvariantCulture System.Globalization.CultureInfo不包含名称的定义 - System.Globalization.CultureInfo does not contain a definition for Name 什么是CultureInfo.GetCultures是.NET Core - What is the equivalent of CultureInfo.GetCultures is .NET Core 为什么不在CultureInfo.GetCultures()中展示所有国家/地区? - Why not all countries are presented in CultureInfo.GetCultures()? System.Globalization.CultureInfo.CurrentUICulture 和 System.Threading.Thread.CurrentUICulture 有什么区别 - What is the difference between System.Globalization.CultureInfo.CurrentUICulture and System.Threading.Thread.CurrentUICulture DNX依赖关系冲突“类型&#39;CultureInfo&#39;在&#39;System.Globalization&#39;和&#39;mscorlib&#39;中都存在”? - DNX dependency conflict “The type 'CultureInfo' exists in both 'System.Globalization' and 'mscorlib'”? 在.NET Windows应用商店应用中替换CultureInfo.GetCultures - Replacement for CultureInfo.GetCultures in .NET Windows Store apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM