EllanJiang/GameFramework · error · GameFrameworkException
Task is invalid.
Error message
Task is invalid.
What it means
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.
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.
Example fix
// before
WebRequestTask task = m_TaskPool.DequeueTask();
agent.Start(task); // task may be null
// after
WebRequestTask task = m_TaskPool.DequeueTask();
if (task != null)
{
agent.Start(task);
} Defensive patterns
Strategy: type-guard
Validate before calling
WebRequestTask task = m_TaskPool.DequeueTask(); if (task == null) return; // nothing to process agent.Start(task);
Type guard
bool IsValidTask(WebRequestTask task) => task != null && !string.IsNullOrEmpty(task.WebRequestUri);
Try / catch
try
{
agent.Start(task);
}
catch (GameFrameworkException ex) when (ex.Message == "Task is invalid.")
{
Log.Error("Attempted to start a null web request task.");
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Web request agent helper is invalid.
- Web request uri is invalid.
- Owner is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/24666b24c8f36c68.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs:114
/// 关闭并清理 Web 请求代理。
/// </summary>
public void Shutdown()
{
Reset();
m_Helper.WebRequestAgentHelperComplete -= OnWebRequestAgentHelperComplete;
m_Helper.WebRequestAgentHelperError -= OnWebRequestAgentHelperError;
}
/// <summary>
/// 开始处理 Web 请求任务。
/// </summary>
/// <param name="task">要处理的 Web 请求任务。</param>
/// <returns>开始处理任务的状态。</returns>
public StartTaskStatus Start(WebRequestTask task)
{
if (task == null)
{
throw new GameFrameworkException("Task is invalid.");
}
m_Task = task;
m_Task.Status = WebRequestTaskStatus.Doing;
if (WebRequestAgentStart != null)
{
WebRequestAgentStart(this);
}
byte[] postData = m_Task.GetPostData();
if (postData == null)
{
m_Helper.Request(m_Task.WebRequestUri, m_Task.UserData);
}
else
{
m_Helper.Request(m_Task.WebRequestUri, postData, m_Task.UserData);View on GitHub (pinned to d0c010b051)