2016-11-21 86 views
1

一空,這很可能是我的一個新手的錯誤,我是相當新的.NET和C#。System.Globalization.CultureInfo.GetCultures返回在開發環境(Visual Studio中)所有的

我使用的是我們最新的項目CMS系統一把umbraco,以及最近的更新意味着該系統已使用System.Globalization.CultureInfo類來處理本地化啓動。這導致CMS後臺中出現多個「Culture Not Found」錯誤,導致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 

我還沒有完全確定,其中,沒有。是從哪裏來的,但經過了一定的研究量到這一點,我試圖運行插入斷點下面的代碼:

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

這返回null,似乎並沒有在任何地方引發異常。我猜這可能是錯誤的原因,由棧跟蹤來判斷。這可能是我的本地設置的問題嗎?我正在運行Windows 10,主要是在虛擬化環境中運行,但它也可以通過OSX Bootcamp本地運行,問題似乎仍然存在。我也嘗試使用Powershell來輸出已安裝文化的列表,並且工作正常。

如果有幫助,我使用IISExpress爲Web服務器和數據庫的SQL Server 2016快速下運行。

在此先感謝!讓我知道我是否可以提供任何額外的信息來幫助解決這個問題。

回答

0

利用的事實,一把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文件;

+0

感謝您的及時答覆。我試着運行一些一把umbraco方法進一步回落的痕跡,似乎有問題查詢的XML文件時,默認爲「恩」文化。有點奇怪的是System.Globalization.CultureInfo。我的開發環境中的GetCultureInfo(「en」)或「en-US」/「en-GB」返回null。爲什麼會這樣? – Mieduzka