{"record":{"id":"d40a8f56d9f271d3","repo":"EllanJiang/GameFramework","slug":"ui-form-helper-is-invalid-uimanager","errorCode":null,"errorMessage":"UI form helper is invalid.","messagePattern":"UI form helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/UI/UIManager.cs","lineNumber":276,"sourceCode":"        public void SetResourceManager(IResourceManager resourceManager)\n        {\n            if (resourceManager == null)\n            {\n                throw new GameFrameworkException(\"Resource manager is invalid.\");\n            }\n\n            m_ResourceManager = resourceManager;\n        }\n\n        /// <summary>\n        /// 设置界面辅助器。\n        /// </summary>\n        /// <param name=\"uiFormHelper\">界面辅助器。</param>\n        public void SetUIFormHelper(IUIFormHelper uiFormHelper)\n        {\n            if (uiFormHelper == null)\n            {\n                throw new GameFrameworkException(\"UI form helper is invalid.\");\n            }\n\n            m_UIFormHelper = uiFormHelper;\n        }\n\n        /// <summary>\n        /// 是否存在界面组。\n        /// </summary>\n        /// <param name=\"uiGroupName\">界面组名称。</param>\n        /// <returns>是否存在界面组。</returns>\n        public bool HasUIGroup(string uiGroupName)\n        {\n            if (string.IsNullOrEmpty(uiGroupName))\n            {\n                throw new GameFrameworkException(\"UI group name is invalid.\");\n            }\n\n            return m_UIGroups.ContainsKey(uiGroupName);","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/UI/UIManager.cs#L258-L294","documentation":"GameFramework's UIManager requires an IUIFormHelper before it can open, close, or manage UI forms. SetUIFormHelper throws this GameFrameworkException when the helper argument is null, because every later UI form operation delegates to m_UIFormHelper and would crash with a NullReferenceException anyway. The throw is an early, explicit fail-fast for a missing mandatory dependency.","triggerScenarios":"Calling SetUIFormHelper(null), typically when helper initialization is conditional or the helper field is not yet assigned at the call site.","commonSituations":"Bootstrap code where the IUIFormHelper implementation is created after the UIManager is used; Unity projects that forgot to register a custom UIFormHelper in their game entry script; refactoring that removed the helper creation but left the SetUIFormHelper call.","solutions":["Pass a non-null IUIFormHelper instance, e.g. m_UIManager.SetUIFormHelper(new UGUIFormHelper())","If the helper is created lazily, ensure it is instantiated before calling SetUIFormHelper or skip the call until it exists","Check that your DI/initialization order constructs the UI helper before the UIManager setup step","Wrap the call in a null check to fail with a clearer application-level message"],"exampleFix":"// before\nUIManager.SetUIFormHelper(m_Config.uiFormHelper); // field may be null\n// after\nvar helper = new UGUIFormHelper();\nUIManager.SetUIFormHelper(helper);","handlingStrategy":"validation","validationCode":"if (uiFormHelper == null) throw new InvalidOperationException(\"UIFormHelper must be created before SetUIFormHelper\");\nuiManager.SetUIFormHelper(uiFormHelper);","typeGuard":"bool IsValidHelper(IUIFormHelper h) => h != null;","tryCatchPattern":"try { uiManager.SetUIFormHelper(helper); }\ncatch (GameFrameworkException ex) { Debug.LogError($\"UI init failed: {ex.Message}\"); }","preventionTips":["Create the UI helper at the very start of the framework initialization sequence","Never pass helper references obtained from fields that may not be assigned yet","Add an assertion in your game entry that all helpers are constructed before UIManager setup"],"tags":["null-argument","ui","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}