EllanJiang/GameFramework · error · GameFrameworkException

Localization helper is invalid.

Error message

Localization helper is invalid.

What it means

SetLocalizationHelper rejects a null ILocalizationHelper. The helper is mandatory for localization to read dictionaries and detect the system language, so installing a null one would corrupt the manager's state for all later calls; the library validates the argument and throws immediately.

Solutions

  1. Pass a valid ILocalizationHelper instance, e.g. localization.SetLocalizationHelper(new DefaultLocalizationHelper()).
  2. Verify the object you pass actually implements ILocalizationHelper and is not null due to a failed load.
  3. Null-check or assert the helper at the call site to fail earlier with a clearer message.

Example fix

// before
m_LocalizationHelper = GetComponent<ILocalizationHelper>(); // may be null
Localization.SetLocalizationHelper(m_LocalizationHelper);

// after
var helper = (ILocalizationHelper)GetComponent<DefaultLocalizationHelper>();
if (helper != null)
{
    Localization.SetLocalizationHelper(helper);
}
Defensive patterns

Strategy: validation

Validate before calling

if (localizationHelper != null)
    Localization.SetLocalizationHelper(localizationHelper);
else
    Log.Error("Localization helper not assigned");

Type guard

static bool IsValidHelper(ILocalizationHelper h) => h != null;

Try / catch

try { Localization.SetLocalizationHelper(helper); }
catch (GameFrameworkException ex) { Log.Error("Helper is null: " + ex.Message); }

Prevention

When it happens

Trigger: Calling SetLocalizationHelper(null), typically because a helper field/component was never assigned or a factory call that was supposed to create the helper returned null.

Common situations: Helper instance not wired up in the Unity inspector; Resources.Load for a helper prefab/asset failed and returned null; a custom helper registered behind a conditional compile flag that is disabled.

Related errors


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

Appendix: source

Thrown at GameFramework/Localization/LocalizationManager.cs:195

        /// <summary>
        /// 设置本地化数据提供者辅助器。
        /// </summary>
        /// <param name="dataProviderHelper">本地化数据提供者辅助器。</param>
        public void SetDataProviderHelper(IDataProviderHelper<ILocalizationManager> dataProviderHelper)
        {
            m_DataProvider.SetDataProviderHelper(dataProviderHelper);
        }

        /// <summary>
        /// 设置本地化辅助器。
        /// </summary>
        /// <param name="localizationHelper">本地化辅助器。</param>
        public void SetLocalizationHelper(ILocalizationHelper localizationHelper)
        {
            if (localizationHelper == null)
            {
                throw new GameFrameworkException("Localization helper is invalid.");
            }

            m_LocalizationHelper = localizationHelper;
        }

        /// <summary>
        /// 确保二进制流缓存分配足够大小的内存并缓存。
        /// </summary>
        /// <param name="ensureSize">要确保二进制流缓存分配内存的大小。</param>
        public void EnsureCachedBytesSize(int ensureSize)
        {
            DataProvider<ILocalizationManager>.EnsureCachedBytesSize(ensureSize);
        }

        /// <summary>
        /// 释放缓存的二进制流。
        /// </summary>
        public void FreeCachedBytes()

View on GitHub (pinned to d0c010b051)