EllanJiang/GameFramework · error · GameFrameworkException

Network channel helper is invalid.

Error message

Network channel helper is invalid.

What it means

GameFramework's NetworkManager refuses to create a network channel when the supplied INetworkChannelHelper is null. The helper provides the packet header length and packet handling logic, so a channel cannot function without it. This is a fail-fast null-argument guard in CreateNetworkChannel.

Solutions

  1. Pass a non-null INetworkChannelHelper instance to CreateNetworkChannel
  2. If the helper comes from a serialized field or factory, check it for null before calling and initialize it
  3. Implement a concrete INetworkChannelHelper (e.g. a subclass of the default helper) if none exists

Example fix

// before
var channel = networkManager.CreateNetworkChannel("game", ServiceType.Tcp, _helper);
// after
if (_helper == null) { _helper = new DefaultNetworkChannelHelper(); }
var channel = networkManager.CreateNetworkChannel("game", ServiceType.Tcp, _helper);
Defensive patterns

Strategy: validation

Validate before calling

if (helper == null) throw new ArgumentNullException(nameof(helper));
var channel = networkManager.CreateNetworkChannel(name, serviceType, helper);

Type guard

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

Try / catch

try { var channel = networkManager.CreateNetworkChannel(name, serviceType, helper); }
catch (GameFrameworkException ex) { Log.Error("Channel helper invalid: {0}", ex.Message); }

Prevention

When it happens

Trigger: Calling CreateNetworkChannel(name, serviceType, null), typically because the helper field was never assigned, a custom helper factory returned null, or a serialized Unity field was left unset.

Common situations: Forgetting to attach a NetworkChannelHelper component in a Unity scene; constructing a channel in code before the helper MonoBehaviour initializes; refactoring that renames the helper class and silently nulls references.

Related errors


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

Appendix: source

Thrown at GameFramework/Network/NetworkManager.cs:229

            results.Clear();
            foreach (KeyValuePair<string, NetworkChannelBase> networkChannel in m_NetworkChannels)
            {
                results.Add(networkChannel.Value);
            }
        }

        /// <summary>
        /// 创建网络频道。
        /// </summary>
        /// <param name="name">网络频道名称。</param>
        /// <param name="serviceType">网络服务类型。</param>
        /// <param name="networkChannelHelper">网络频道辅助器。</param>
        /// <returns>要创建的网络频道。</returns>
        public INetworkChannel CreateNetworkChannel(string name, ServiceType serviceType, INetworkChannelHelper networkChannelHelper)
        {
            if (networkChannelHelper == null)
            {
                throw new GameFrameworkException("Network channel helper is invalid.");
            }

            if (networkChannelHelper.PacketHeaderLength < 0)
            {
                throw new GameFrameworkException("Packet header length is invalid.");
            }

            if (HasNetworkChannel(name))
            {
                throw new GameFrameworkException(Utility.Text.Format("Already exist network channel '{0}'.", name ?? string.Empty));
            }

            NetworkChannelBase networkChannel = null;
            switch (serviceType)
            {
                case ServiceType.Tcp:
                    networkChannel = new TcpNetworkChannel(name, networkChannelHelper);
                    break;

View on GitHub (pinned to d0c010b051)