EllanJiang/GameFramework · error · GameFrameworkException

Already exist network channel

Error message

Already exist network channel '{0}'.

What it means

NetworkManager keys channels by name and does not allow duplicates. CreateNetworkChannel throws this formatted error when a channel with the same name already exists. The caller must dispose the old channel or choose a unique name.

Solutions

  1. Check HasNetworkChannel(name) before creating and reuse or destroy the existing channel
  2. Call DestroyNetworkChannel(name) before re-creating
  3. Generate unique names, e.g. append a counter or connection id

Example fix

// before
var channel = networkManager.CreateNetworkChannel("game", ServiceType.Tcp, helper);
// after
if (networkManager.HasNetworkChannel("game")) { networkManager.DestroyNetworkChannel("game"); }
var channel = networkManager.CreateNetworkChannel("game", ServiceType.Tcp, helper);
Defensive patterns

Strategy: validation

Validate before calling

if (networkManager.HasNetworkChannel(name)) networkManager.DestroyNetworkChannel(name);
var channel = networkManager.CreateNetworkChannel(name, serviceType, helper);

Try / catch

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

Prevention

When it happens

Trigger: Calling CreateNetworkChannel twice with the same name string without calling DestroyNetworkChannel in between, e.g. on reconnect logic or scene reload that re-runs initialization.

Common situations: Reconnect handlers that rebuild channels without tearing down the previous one; duplicate initialization from both Start and OnEnable; name collisions when opening multiple connections built from a shared naming template.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at GameFramework/Network/NetworkManager.cs:239

        /// <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;

                case ServiceType.TcpWithSyncReceive:
                    networkChannel = new TcpWithSyncReceiveNetworkChannel(name, networkChannelHelper);
                    break;

                default:
                    throw new GameFrameworkException(Utility.Text.Format("Not supported service type '{0}'.", serviceType));
            }

            networkChannel.NetworkChannelConnected += OnNetworkChannelConnected;

View on GitHub (pinned to d0c010b051)