{"record":{"id":"24666b24c8f36c68","repo":"EllanJiang/GameFramework","slug":"task-is-invalid-webrequestmanager-webrequestagent","errorCode":null,"errorMessage":"Task is invalid.","messagePattern":"Task is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs","lineNumber":114,"sourceCode":"            /// 关闭并清理 Web 请求代理。\n            /// </summary>\n            public void Shutdown()\n            {\n                Reset();\n                m_Helper.WebRequestAgentHelperComplete -= OnWebRequestAgentHelperComplete;\n                m_Helper.WebRequestAgentHelperError -= OnWebRequestAgentHelperError;\n            }\n\n            /// <summary>\n            /// 开始处理 Web 请求任务。\n            /// </summary>\n            /// <param name=\"task\">要处理的 Web 请求任务。</param>\n            /// <returns>开始处理任务的状态。</returns>\n            public StartTaskStatus Start(WebRequestTask task)\n            {\n                if (task == null)\n                {\n                    throw new GameFrameworkException(\"Task is invalid.\");\n                }\n\n                m_Task = task;\n                m_Task.Status = WebRequestTaskStatus.Doing;\n\n                if (WebRequestAgentStart != null)\n                {\n                    WebRequestAgentStart(this);\n                }\n\n                byte[] postData = m_Task.GetPostData();\n                if (postData == null)\n                {\n                    m_Helper.Request(m_Task.WebRequestUri, m_Task.UserData);\n                }\n                else\n                {\n                    m_Helper.Request(m_Task.WebRequestUri, postData, m_Task.UserData);","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs#L96-L132","documentation":"WebRequestAgent.Start throws GameFrameworkException with 'Task is invalid.' when handed a null WebRequestTask to process. The agent stores the task, marks it Doing, and fires the WebRequestAgentStart event, so a null task would break all of these steps; the library rejects it at the entry point.","triggerScenarios":"The task-processing loop in WebRequestManager pops from the task pool but the agent's Start is invoked with a null task (dequeued task is null).","commonSituations":"Custom task pool usage or a modified WebRequestManager scheduling loop that does not check for a null dequeue result before assigning the task to an agent.","solutions":["Ensure the task pool dequeue result is checked for null before calling agent.Start(task).","Do not call Start manually with an unvalidated task; let WebRequestManager's internal loop drive agents.","If custom code feeds tasks, create tasks only via WebRequestTask.Create and never enqueue null."],"exampleFix":"// before\nWebRequestTask task = m_TaskPool.DequeueTask();\nagent.Start(task); // task may be null\n// after\nWebRequestTask task = m_TaskPool.DequeueTask();\nif (task != null)\n{\n    agent.Start(task);\n}","handlingStrategy":"type-guard","validationCode":"WebRequestTask task = m_TaskPool.DequeueTask();\nif (task == null) return; // nothing to process\nagent.Start(task);","typeGuard":"bool IsValidTask(WebRequestTask task) => task != null && !string.IsNullOrEmpty(task.WebRequestUri);","tryCatchPattern":"try\n{\n    agent.Start(task);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Task is invalid.\")\n{\n    Log.Error(\"Attempted to start a null web request task.\");\n}","preventionTips":["Always check the dequeue result of a task pool for null before dispatching.","Never call agent.Start manually outside WebRequestManager's processing loop.","Only create tasks through WebRequestTask.Create."],"tags":["csharp","gameframework","webrequest","null-argument","task"],"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"}