I've two Reources in Properties/String/ (cs-CZ.resx;default.resx)

I set it up this way:

    internal static System.Resources.ResourceManager strings;

    public static void SetLanguage(string culture)
    {
        if (culture == "cs-CZ")
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ");
            strings = Properties.Strings.cs_CZ.ResourceManager;
        }
        else
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            strings = Properties.Strings._default.ResourceManager;
        }
    }

In Form constructor:

    SetLanguage("cs-CZ");

And then

    public static string Translate(string name)
    {
        return strings.GetString(name);
    }

mainStrip.Text = Translate("mainStrip");

But I'm getting TypeInitializationException. Whats wrong?

没有正确的解决方案

其他提示

TypeInitializationException is caused mainly using private static constructor. Calling SetLanguage method will call this constructor and it thrown this exception. So create new Class for this or call constructor before this method.

Fxp. here it's nice example: http://www.dotnetperls.com/typeinitializationexception

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top