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

  1. Ensure the task pool dequeue result is checked for null before calling agent.Start(task).
  2. Do not call Start manually with an unvalidated task; let WebRequestManager's internal loop drive agents.
  3. 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

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


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)