gpt4 book ai didi

c#-4.0 - CultureNotFoundException : Culture is not supported after upgrading to . 净 4

转载 作者:行者123 更新时间:2023-12-02 00:34:43 29 4
gpt4 key购买 nike

我们使用 CultureInfo(customCulture) 将文化设置为自定义文化

为了以防万一,我们在 app_start 的 global.cs 中创建了 customCulture。

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

同样的代码在 3.5 下运行良好?

最佳答案

为了防止其他人遇到这个问题,我不得不编写一个命令行工具来注销文化,然后重新注册。

        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");
}
}
}

关于c#-4.0 - CultureNotFoundException : Culture is not supported after upgrading to . 净 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5094973/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com