EllanJiang/GameFramework · error · GameFrameworkException

Web request agent helper is invalid.

Error message

Web request agent helper is invalid.

What it means

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.

Solutions

  1. Ensure the factory passed to AddAgent/CreateHelper returns a valid IWebRequestAgentHelper instance (e.g. new UnityWebRequestAgentHelper()).
  2. Verify the assembly containing the helper class is referenced and deployed with the build.
  3. Check that no custom CreateHelper override can return null; add a factory-level null check.

Example fix

// before
m_WebRequestManager.AddAgent((HelperClass) => null);
// after
m_WebRequestManager.AddAgent((HelperClass) => HelperClass == null ? null : (IWebRequestAgentHelper)HelperClass.Invoke());
// better: return a real helper
m_WebRequestManager.AddAgent((HelperClass) => (IWebRequestAgentHelper)HelperClass.Invoke());
Defensive patterns

Strategy: try-catch

Validate before calling

IWebRequestAgentHelper helper = CreateHelper();
if (helper == null)
{
    Log.Error("WebRequest helper factory returned null; fix registration.");
    return;
}
m_WebRequestManager.AddAgent((t) => helper);

Type guard

bool IsValidHelper(IWebRequestAgentHelper h) => h != null;

Try / catch

try
{
    m_WebRequestManager.AddAgent(helperType);
}
catch (GameFrameworkException ex) when (ex.Message == "Web request agent helper is invalid.")
{
    Log.Fatal("WebRequest agent helper creation failed: {0}", ex.Message);
}

Prevention

When it happens

Trigger: Calling new WebRequestManager.WebRequestAgent(null), typically from AddAgent with a null helper produced by CreateHelper<TResult>.

Common situations: 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.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/4ae7954b123cb944. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/WebRequest/WebRequestManager.WebRequestAgent.cs:33

        private sealed class WebRequestAgent : ITaskAgent<WebRequestTask>
        {
            private readonly IWebRequestAgentHelper m_Helper;
            private WebRequestTask m_Task;
            private float m_WaitTime;

            public GameFrameworkAction<WebRequestAgent> WebRequestAgentStart;
            public GameFrameworkAction<WebRequestAgent, byte[]> WebRequestAgentSuccess;
            public GameFrameworkAction<WebRequestAgent, string> WebRequestAgentFailure;

            /// <summary>
            /// 初始化 Web 请求代理的新实例。
            /// </summary>
            /// <param name="webRequestAgentHelper">Web 请求代理辅助器。</param>
            public WebRequestAgent(IWebRequestAgentHelper webRequestAgentHelper)
            {
                if (webRequestAgentHelper == null)
                {
                    throw new GameFrameworkException("Web request agent helper is invalid.");
                }

                m_Helper = webRequestAgentHelper;
                m_Task = null;
                m_WaitTime = 0f;

                WebRequestAgentStart = null;
                WebRequestAgentSuccess = null;
                WebRequestAgentFailure = null;
            }

            /// <summary>
            /// 获取 Web 请求任务。
            /// </summary>
            public WebRequestTask Task
            {
                get
                {

View on GitHub (pinned to d0c010b051)