{"record":{"id":"4ae7954b123cb944","repo":"EllanJiang/GameFramework","slug":"web-request-agent-helper-is-invalid","errorCode":null,"errorMessage":"Web request agent helper is invalid.","messagePattern":"Web request agent helper is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs","lineNumber":33,"sourceCode":"        private sealed class WebRequestAgent : ITaskAgent<WebRequestTask>\n        {\n            private readonly IWebRequestAgentHelper m_Helper;\n            private WebRequestTask m_Task;\n            private float m_WaitTime;\n\n            public GameFrameworkAction<WebRequestAgent> WebRequestAgentStart;\n            public GameFrameworkAction<WebRequestAgent, byte[]> WebRequestAgentSuccess;\n            public GameFrameworkAction<WebRequestAgent, string> WebRequestAgentFailure;\n\n            /// <summary>\n            /// 初始化 Web 请求代理的新实例。\n            /// </summary>\n            /// <param name=\"webRequestAgentHelper\">Web 请求代理辅助器。</param>\n            public WebRequestAgent(IWebRequestAgentHelper webRequestAgentHelper)\n            {\n                if (webRequestAgentHelper == null)\n                {\n                    throw new GameFrameworkException(\"Web request agent helper is invalid.\");\n                }\n\n                m_Helper = webRequestAgentHelper;\n                m_Task = null;\n                m_WaitTime = 0f;\n\n                WebRequestAgentStart = null;\n                WebRequestAgentSuccess = null;\n                WebRequestAgentFailure = null;\n            }\n\n            /// <summary>\n            /// 获取 Web 请求任务。\n            /// </summary>\n            public WebRequestTask Task\n            {\n                get\n                {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs#L15-L51","documentation":"WebRequestManager.WebRequestAgent's constructor throws GameFrameworkException with 'Web request agent helper is invalid.' when constructed with a null IWebRequestAgentHelper. Each agent requires exactly one helper that performs the actual HTTP work; without it the agent cannot function, so the constructor rejects null immediately.","triggerScenarios":"Calling new WebRequestManager.WebRequestAgent(null), typically from AddAgent with a null helper produced by CreateHelper<TResult>.","commonSituations":"A custom helper factory returned null; a game logic assembly with the helper implementation was missing (DLL not deployed); a typo in helper type registration with a null-returning helper factory registered.","solutions":["Ensure the factory passed to AddAgent/CreateHelper returns a valid IWebRequestAgentHelper instance (e.g. new UnityWebRequestAgentHelper()).","Verify the assembly containing the helper class is referenced and deployed with the build.","Check that no custom CreateHelper override can return null; add a factory-level null check."],"exampleFix":"// before\nm_WebRequestManager.AddAgent((HelperClass) => null);\n// after\nm_WebRequestManager.AddAgent((HelperClass) => HelperClass == null ? null : (IWebRequestAgentHelper)HelperClass.Invoke());\n// better: return a real helper\nm_WebRequestManager.AddAgent((HelperClass) => (IWebRequestAgentHelper)HelperClass.Invoke());","handlingStrategy":"try-catch","validationCode":"IWebRequestAgentHelper helper = CreateHelper();\nif (helper == null)\n{\n    Log.Error(\"WebRequest helper factory returned null; fix registration.\");\n    return;\n}\nm_WebRequestManager.AddAgent((t) => helper);","typeGuard":"bool IsValidHelper(IWebRequestAgentHelper h) => h != null;","tryCatchPattern":"try\n{\n    m_WebRequestManager.AddAgent(helperType);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Web request agent helper is invalid.\")\n{\n    Log.Fatal(\"WebRequest agent helper creation failed: {0}\", ex.Message);\n}","preventionTips":["Never register a factory/Activator call that can return null; assert in the factory.","Keep helper classes in an assembly that ships with all build targets.","Initialize agents in one well-tested bootstrap method."],"tags":["csharp","gameframework","webrequest","null-argument","constructor"],"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"}