{"record":{"id":"1702f158a99949ab","repo":"EllanJiang/GameFramework","slug":"setting-helper-is-invalid","errorCode":null,"errorMessage":"Setting helper is invalid.","messagePattern":"Setting helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Setting/SettingManager.cs","lineNumber":37,"sourceCode":"\n        /// <summary>\n        /// 初始化游戏配置管理器的新实例。\n        /// </summary>\n        public SettingManager()\n        {\n            m_SettingHelper = null;\n        }\n\n        /// <summary>\n        /// 获取游戏配置项数量。\n        /// </summary>\n        public int Count\n        {\n            get\n            {\n                if (m_SettingHelper == null)\n                {\n                    throw new GameFrameworkException(\"Setting helper is invalid.\");\n                }\n\n                return m_SettingHelper.Count;\n            }\n        }\n\n        /// <summary>\n        /// 游戏配置管理器轮询。\n        /// </summary>\n        /// <param name=\"elapseSeconds\">逻辑流逝时间，以秒为单位。</param>\n        /// <param name=\"realElapseSeconds\">真实流逝时间，以秒为单位。</param>\n        internal override void Update(float elapseSeconds, float realElapseSeconds)\n        {\n        }\n\n        /// <summary>\n        /// 关闭并清理游戏配置管理器。\n        /// </summary>","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Setting/SettingManager.cs#L19-L55","documentation":"SettingManager.Count reads through m_SettingHelper, the ISettingHelper injected via SetSettingHelper. If no helper was set, the property cannot delegate and throws this GameFrameworkException. Several other SettingManager members perform the same guard.","triggerScenarios":"Accessing SettingManager.Count (or other members that touch the helper) before calling SetSettingHelper with a valid ISettingHelper instance.","commonSituations":"Forgetting to register a setting helper (e.g. PlayerPrefsSettingHelper) in GameEntry; using a bare SettingManager in tests; component initialization ordering where settings are read before setup completes.","solutions":["Call SetSettingHelper with a concrete ISettingHelper implementation during initialization.","Ensure GameEntry/component setup order initializes the SettingComponent before any settings access.","Guard settings access behind an initialized check when using SettingManager standalone."],"exampleFix":"// before\nint count = m_SettingManager.Count;\n// after\nm_SettingManager.SetSettingHelper(new DefaultSettingHelper());\nint count = m_SettingManager.Count;","handlingStrategy":"validation","validationCode":"if (settingHelper == null)\n{\n    throw new InvalidOperationException(\"Call SetSettingHelper before using SettingManager.\");\n}","typeGuard":null,"tryCatchPattern":"try { int count = settingManager.Count; }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"Setting helper\"))\n{ Log.Error(\"SettingManager not initialized.\"); }","preventionTips":["Register the ISettingHelper in GameEntry during startup","Expose settings access only through initialized wrappers","Write an init-order unit test for framework components"],"tags":["gameframework","settings","missing-dependency","initialization-order"],"backgroundTag":"missing-dependency","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}