2011-02-23 83 views
3

我们设置区域性使用的CultureInfo(customCulture)定制文化CultureNotFoundException:升级到.NET 4

我们刚创建的情况下在global.cs的customCulture在app_start后不支持文化。

在我的本地PC上,这工作正常。 但是,在Web服务器上,当我去设置文化时,我得到的文化不支持的错误? 我检查过Windows \ Globalization文件夹,那里有一个文化文件,用于正确的文化?

相同的代码在3.5下工作正常吗?

+0

哈哈谢谢!任何有用的建议:)? 它阻止我们切换到自定义的文化,这意味着我们不能用我们的升级现场去.NET 4.0的一半我们的客户群使用自定义的文化,所以我们可以呈现出不同的字符串我们RESX文件的 – Bernard

回答

2

如果有其他人遇到这个问题,我必须编写一个命令行工具来注销文化,然后重新注册它。

 using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Globalization; 

    namespace InstallCulture 
    { 
     class Program 
     { 
      static void Main(string[] args) 
      { 
       // Is CustomCulture already installed? 
       string parentCultureName = "en-GB"; 
       string extendedName = "custom"; 
       System.Globalization.CultureInfo[] userCultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.UserCustomCulture); 
       Console.WriteLine(string.Format("number of user cultures:{0}", userCultures.Count())); 
       Console.WriteLine(string.Format("Setting culture {0}-{1}", parentCultureName, extendedName)); 
       // Install CustomCulture based on language parent. 
       System.Globalization.CultureAndRegionInfoBuilder builder = new System.Globalization.CultureAndRegionInfoBuilder(
         string.Format("{0}-{1}", parentCultureName, extendedName), 
         System.Globalization.CultureAndRegionModifiers.None); 

       builder.LoadDataFromCultureInfo(new System.Globalization.CultureInfo("en-GB")); 
       builder.LoadDataFromRegionInfo(new System.Globalization.RegionInfo("GB")); 
       Console.WriteLine("CultureName:. . . . . . . . . . {0}", builder.CultureName); 
       Console.WriteLine("CultureEnglishName: . . . . . . {0}", builder.CultureEnglishName); 
       Console.WriteLine("CultureNativeName:. . . . . . . {0}", builder.CultureNativeName); 

       foreach(System.Globalization.CultureInfo cultInfo in userCultures) 
       { 
        Console.WriteLine("Found culture in userCultures"); 
        if(cultInfo.Name.ToLower() == string.Format("{0}-{1}", parentCultureName, extendedName).ToLower()) 
        { 
         Console.WriteLine(string.Format("{0} already registered", cultInfo.Name)); 
         CultureAndRegionInfoBuilder.Unregister("en-GB-custom"); 
         Console.WriteLine("Unregistered culture en-GB-custom"); 
        } 
       } 

       Console.WriteLine("Registering culture en-GB-PolHol"); 
       builder.Register(); 
       Console.WriteLine("Create new culture info object"); 
       System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-GB-custom"); 
       Console.WriteLine("Name: . . . . . . . . . . . . . {0}", culture.Name); 
       Console.WriteLine("EnglishName:. . . . . . . . . . {0}", culture.EnglishName); 
       Console.WriteLine("NativeName: . . . . . . . . . . {0}", culture.NativeName); 
       Console.WriteLine("Set threads to new culture"); 
       System.Threading.Thread.CurrentThread.CurrentCulture = culture; 
       System.Threading.Thread.CurrentThread.CurrentUICulture = culture; 
       Console.WriteLine("Set culture done"); 
      } 
     } 
    } 
1

我遵循了如何添加自定义文化和本地机器,如果工作完美的众多指南。但是,在名称上出现错误的开发服务器上,CultureInfo构造函数中发生了CultureNotFoundException。 nlp文件创建正确,我怀疑注册表步骤是问题,但我找不到任何有关它的资源。更重要的是,它破坏了机器上所有其他应用程序的其他语言映射。

最后,我跟着的开发者指南,以构建全球Windows和Web应用程序:第11章 - 在CodeProject定制文化,并与必要的修改,其正常工作取代了现有的文化。

不过我不知道为什么我原来的风俗文化没有工作和更换一样。无论如何,我也想分享我的经验。

+0

您可以发布链接到CodeProject的页面?谢谢 – Hannish