{"record":{"id":"c15e90615965af05","repo":"EllanJiang/GameFramework","slug":"localization-helper-is-invalid","errorCode":null,"errorMessage":"Localization helper is invalid.","messagePattern":"Localization helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Localization/LocalizationManager.cs","lineNumber":195,"sourceCode":"\n        /// <summary>\n        /// 设置本地化数据提供者辅助器。\n        /// </summary>\n        /// <param name=\"dataProviderHelper\">本地化数据提供者辅助器。</param>\n        public void SetDataProviderHelper(IDataProviderHelper<ILocalizationManager> dataProviderHelper)\n        {\n            m_DataProvider.SetDataProviderHelper(dataProviderHelper);\n        }\n\n        /// <summary>\n        /// 设置本地化辅助器。\n        /// </summary>\n        /// <param name=\"localizationHelper\">本地化辅助器。</param>\n        public void SetLocalizationHelper(ILocalizationHelper localizationHelper)\n        {\n            if (localizationHelper == null)\n            {\n                throw new GameFrameworkException(\"Localization helper is invalid.\");\n            }\n\n            m_LocalizationHelper = localizationHelper;\n        }\n\n        /// <summary>\n        /// 确保二进制流缓存分配足够大小的内存并缓存。\n        /// </summary>\n        /// <param name=\"ensureSize\">要确保二进制流缓存分配内存的大小。</param>\n        public void EnsureCachedBytesSize(int ensureSize)\n        {\n            DataProvider<ILocalizationManager>.EnsureCachedBytesSize(ensureSize);\n        }\n\n        /// <summary>\n        /// 释放缓存的二进制流。\n        /// </summary>\n        public void FreeCachedBytes()","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Localization/LocalizationManager.cs#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a valid ILocalizationHelper instance, e.g. localization.SetLocalizationHelper(new DefaultLocalizationHelper()).","Verify the object you pass actually implements ILocalizationHelper and is not null due to a failed load.","Null-check or assert the helper at the call site to fail earlier with a clearer message."],"exampleFix":"// before\nm_LocalizationHelper = GetComponent<ILocalizationHelper>(); // may be null\nLocalization.SetLocalizationHelper(m_LocalizationHelper);\n\n// after\nvar helper = (ILocalizationHelper)GetComponent<DefaultLocalizationHelper>();\nif (helper != null)\n{\n    Localization.SetLocalizationHelper(helper);\n}","handlingStrategy":"validation","validationCode":"if (localizationHelper != null)\n    Localization.SetLocalizationHelper(localizationHelper);\nelse\n    Log.Error(\"Localization helper not assigned\");","typeGuard":"static bool IsValidHelper(ILocalizationHelper h) => h != null;","tryCatchPattern":"try { Localization.SetLocalizationHelper(helper); }\ncatch (GameFrameworkException ex) { Log.Error(\"Helper is null: \" + ex.Message); }","preventionTips":["Check inspector/asset references for the helper before calling SetLocalizationHelper.","Fail fast in your own bootstrap if the helper could not be created.","Prefer instantiating a concrete helper (e.g. DefaultLocalizationHelper) over GetComponent-based lookup that can return null."],"tags":["localization","null-argument","validation"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}