{"record":{"id":"cc82c77a212a97bf","repo":"EllanJiang/GameFramework","slug":"network-channel-helper-is-invalid","errorCode":null,"errorMessage":"Network channel helper is invalid.","messagePattern":"Network channel helper is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Network/NetworkManager.cs","lineNumber":229,"sourceCode":"            results.Clear();\n            foreach (KeyValuePair<string, NetworkChannelBase> networkChannel in m_NetworkChannels)\n            {\n                results.Add(networkChannel.Value);\n            }\n        }\n\n        /// <summary>\n        /// 创建网络频道。\n        /// </summary>\n        /// <param name=\"name\">网络频道名称。</param>\n        /// <param name=\"serviceType\">网络服务类型。</param>\n        /// <param name=\"networkChannelHelper\">网络频道辅助器。</param>\n        /// <returns>要创建的网络频道。</returns>\n        public INetworkChannel CreateNetworkChannel(string name, ServiceType serviceType, INetworkChannelHelper networkChannelHelper)\n        {\n            if (networkChannelHelper == null)\n            {\n                throw new GameFrameworkException(\"Network channel helper is invalid.\");\n            }\n\n            if (networkChannelHelper.PacketHeaderLength < 0)\n            {\n                throw new GameFrameworkException(\"Packet header length is invalid.\");\n            }\n\n            if (HasNetworkChannel(name))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Already exist network channel '{0}'.\", name ?? string.Empty));\n            }\n\n            NetworkChannelBase networkChannel = null;\n            switch (serviceType)\n            {\n                case ServiceType.Tcp:\n                    networkChannel = new TcpNetworkChannel(name, networkChannelHelper);\n                    break;","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Network/NetworkManager.cs#L211-L247","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a non-null INetworkChannelHelper instance to CreateNetworkChannel","If the helper comes from a serialized field or factory, check it for null before calling and initialize it","Implement a concrete INetworkChannelHelper (e.g. a subclass of the default helper) if none exists"],"exampleFix":"// before\nvar channel = networkManager.CreateNetworkChannel(\"game\", ServiceType.Tcp, _helper);\n// after\nif (_helper == null) { _helper = new DefaultNetworkChannelHelper(); }\nvar channel = networkManager.CreateNetworkChannel(\"game\", ServiceType.Tcp, _helper);","handlingStrategy":"validation","validationCode":"if (helper == null) throw new ArgumentNullException(nameof(helper));\nvar channel = networkManager.CreateNetworkChannel(name, serviceType, helper);","typeGuard":"bool IsValidHelper(INetworkChannelHelper h) => h != null;","tryCatchPattern":"try { var channel = networkManager.CreateNetworkChannel(name, serviceType, helper); }\ncatch (GameFrameworkException ex) { Log.Error(\"Channel helper invalid: {0}\", ex.Message); }","preventionTips":["Assign helper fields in Awake/constructor, never rely on late initialization","Assert non-null helper at startup","Prefer concrete default helper subclasses over ad-hoc implementations"],"tags":["network","null-argument","gameframework"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}