errors while using OSGi.NET

May 16, 2013 at 6:24 AM
Edited May 16, 2013 at 8:07 AM
我添加以下语句到web.config文件中,MVC4 demo工程就不能正常显示了, IIS express会强制关闭,不知道哪部分代码出现了异常!
<system.web>
       <globalization uiCulture="auto:en" culture="auto:en-GB" enableClientBasedCulture="true" />
   </system.web>
Coordinator
May 22, 2013 at 8:39 AM
在VS中按组合键Ctrl+D+E,勾选上“Common Language Runtime Exception“,会有如下提示
Culture is not supported.
Parameter name: name
UserCache is an invalid culture identifier.

可以参考 http://stackoverflow.com/a/6302012

切换到VS Deveopement Server不会出现这个异常。
May 23, 2013 at 1:20 AM
Edited May 23, 2013 at 1:23 AM
在我的项目中,我需要做多语言切换。我添加了一个全局的Filter:
public class LanguageFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var request = filterContext.HttpContext.Request;
            string cultureName = null;
            var cultureCookie = request.Cookies["_culture"];
            if (request.UserLanguages != null)
                cultureName = cultureCookie != null ? cultureCookie.Value : request.UserLanguages[0];
            cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
            Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

            base.OnActionExecuting(filterContext);
        }
    }
如果我将cultureName直接赋值“zh-CN"(我用的中文系统),程序就能正常运行;但如果赋值非本系统的语言,如:en-GB,en-US, 那么程序就会中断。但是我整个项目工程在没有引用OSGi.NET的时候,一切都可以正常运行。

所以是不是我更改了Thread.CurrentThread.CurrentCulture这个值,引起OSGi.NET内部错误?
Coordinator
May 23, 2013 at 5:56 AM
rqx110 wrote:
所以是不是我更改了Thread.CurrentThread.CurrentCulture这个值,引起OSGi.NET内部错误?
如果是内核错误,应该会在log.txt中有详细记录,一般在Web Application的bin目录中。
May 23, 2013 at 7:41 AM
经过调试好像我在设置Thread.CurrentThread.CurrentCulture后,UIShell.OSGi.MvcCore.BundleRazorViewEngine的FindView方法会无法找到插件中的对应View。
Coordinator
May 24, 2013 at 2:47 PM
rqx110 wrote:
经过调试好像我在设置Thread.CurrentThread.CurrentCulture后,UIShell.OSGi.MvcCore.BundleRazorViewEngine的FindView方法会无法找到插件中的对应View。
谢谢您的反馈,我们会研究一下。
Coordinator
May 27, 2013 at 7:29 AM
Hi,
This bug has been fixed in OSGi.net assembly, to work this around for the current version, please put below line to the first line of Application_Start() method,
UIShell.OSGi.Utility.Messages.Culture = new System.Globalization.CultureInfo("en-US");

Thanks,
May 28, 2013 at 7:10 AM
Where to download the new OSGi.net assembly?