EllanJiang/GameFramework · error · GameFrameworkException

Language is invalid.

Error message

Language is invalid.

What it means

The LocalizationManager.Language property setter rejects Language.Unspecified. Language is an enum and Unspecified is the sentinel meaning 'no language chosen'; assigning it to the manager would leave the localization system in an undefined state, so the library throws instead of accepting it.

Solutions

  1. Assign a concrete language, e.g. localization.Language = Language.English.
  2. Guard with if (lang != Language.Unspecified) before setting the property.
  3. If the language came from config, provide a non-Unspecified default (e.g. fall back to English) when parsing fails.

Example fix

// before
Localization.Language = (Language)savedInt; // may be Language.Unspecified

// after
var lang = (Language)savedInt;
if (lang != Language.Unspecified)
{
    Localization.Language = lang;
}
else
{
    Localization.Language = Language.English;
}
Defensive patterns

Strategy: validation

Validate before calling

if (System.Enum.IsDefined(typeof(Language), lang) && lang != Language.Unspecified)
{
    Localization.Language = lang;
}

Type guard

static bool IsValidLanguage(Language l) => l != Language.Unspecified && System.Enum.IsDefined(typeof(Language), l);

Try / catch

try { Localization.Language = lang; }
catch (GameFrameworkException) { Localization.Language = Language.English; }

Prevention

When it happens

Trigger: Assigning localization.Language = Language.Unspecified directly, or copying a Language value read from uninitialized data/config/UI that defaulted to Unspecified.

Common situations: Binding the property to a UI dropdown whose default selected value maps to Unspecified; deserializing a settings file where the language field was missing and the enum defaulted to 0 (Unspecified); propagating a failed system-language lookup as Unspecified instead of a concrete language.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/134a4310d314c72a. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Localization/LocalizationManager.cs:48

            m_DataProvider = new DataProvider<ILocalizationManager>(this);
            m_LocalizationHelper = null;
            m_Language = Language.Unspecified;
        }

        /// <summary>
        /// 获取或设置本地化语言。
        /// </summary>
        public Language Language
        {
            get
            {
                return m_Language;
            }
            set
            {
                if (value == Language.Unspecified)
                {
                    throw new GameFrameworkException("Language is invalid.");
                }

                m_Language = value;
            }
        }

        /// <summary>
        /// 获取系统语言。
        /// </summary>
        public Language SystemLanguage
        {
            get
            {
                if (m_LocalizationHelper == null)
                {
                    throw new GameFrameworkException("You must set localization helper first.");
                }

View on GitHub (pinned to d0c010b051)