문제

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