EllanJiang/GameFramework · error · GameFrameworkException

Results is invalid.

Error message

Results is invalid.

What it means

NetworkManager.GetAllNetworkChannels copies all registered channels into the caller-supplied List<INetworkChannel>; a null list is rejected with GameFrameworkException. The method clears and fills the list but will not allocate it for you.

Solutions

  1. Instantiate the list before calling: new List<INetworkChannel>().
  2. Null-check the list argument in wrappers around this API.
  3. Prefer GetNetworkChannels (allocating variant) if available, or wrap the call in a helper that allocates.

Example fix

// before
List<INetworkChannel> channels = null;
networkManager.GetAllNetworkChannels(channels);
// after
List<INetworkChannel> channels = new List<INetworkChannel>();
networkManager.GetAllNetworkChannels(channels);
Defensive patterns

Strategy: type-guard

Validate before calling

if (results == null) results = new List<INetworkChannel>(); networkManager.GetAllNetworkChannels(results);

Type guard

public static bool HasResultList<T>(List<T> list) => list != null;

Try / catch

try { networkManager.GetAllNetworkChannels(results); } catch (GameFrameworkException ex) when (ex.Message == "Results is invalid.") { results = new List<INetworkChannel>(); networkManager.GetAllNetworkChannels(results); }

Prevention

When it happens

Trigger: Calling GetAllNetworkChannels(null); passing an uninitialized list variable that was never instantiated.

Common situations: Refactors that changed an initialized field to a property never assigned; codegen or DI setups that leave the list null; copy-paste from APIs that allocate the result for the caller.

Related errors


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

Appendix: source

Thrown at GameFramework/Network/NetworkManager.cs:208

            int index = 0;
            INetworkChannel[] results = new INetworkChannel[m_NetworkChannels.Count];
            foreach (KeyValuePair<string, NetworkChannelBase> networkChannel in m_NetworkChannels)
            {
                results[index++] = networkChannel.Value;
            }

            return results;
        }

        /// <summary>
        /// 获取所有网络频道。
        /// </summary>
        /// <param name="results">所有网络频道。</param>
        public void GetAllNetworkChannels(List<INetworkChannel> results)
        {
            if (results == null)
            {
                throw new GameFrameworkException("Results is invalid.");
            }

            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)
        {

View on GitHub (pinned to d0c010b051)