Frage

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?

Keine korrekte Lösung

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top