{"record":{"id":"f37b40f82cceafd1","repo":"EllanJiang/GameFramework","slug":"results-is-invalid-networkmanager","errorCode":null,"errorMessage":"Results is invalid.","messagePattern":"Results is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Network/NetworkManager.cs","lineNumber":208,"sourceCode":"            int index = 0;\n            INetworkChannel[] results = new INetworkChannel[m_NetworkChannels.Count];\n            foreach (KeyValuePair<string, NetworkChannelBase> networkChannel in m_NetworkChannels)\n            {\n                results[index++] = networkChannel.Value;\n            }\n\n            return results;\n        }\n\n        /// <summary>\n        /// 获取所有网络频道。\n        /// </summary>\n        /// <param name=\"results\">所有网络频道。</param>\n        public void GetAllNetworkChannels(List<INetworkChannel> results)\n        {\n            if (results == null)\n            {\n                throw new GameFrameworkException(\"Results is invalid.\");\n            }\n\n            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        {","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Network/NetworkManager.cs#L190-L226","documentation":"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.","triggerScenarios":"Calling GetAllNetworkChannels(null); passing an uninitialized list variable that was never instantiated.","commonSituations":"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.","solutions":["Instantiate the list before calling: new List<INetworkChannel>().","Null-check the list argument in wrappers around this API.","Prefer GetNetworkChannels (allocating variant) if available, or wrap the call in a helper that allocates."],"exampleFix":"// before\nList<INetworkChannel> channels = null;\nnetworkManager.GetAllNetworkChannels(channels);\n// after\nList<INetworkChannel> channels = new List<INetworkChannel>();\nnetworkManager.GetAllNetworkChannels(channels);","handlingStrategy":"type-guard","validationCode":"if (results == null) results = new List<INetworkChannel>(); networkManager.GetAllNetworkChannels(results);","typeGuard":"public static bool HasResultList<T>(List<T> list) => list != null;","tryCatchPattern":"try { networkManager.GetAllNetworkChannels(results); } catch (GameFrameworkException ex) when (ex.Message == \"Results is invalid.\") { results = new List<INetworkChannel>(); networkManager.GetAllNetworkChannels(results); }","preventionTips":["Always allocate result containers before calling *All* APIs","Enable nullable reference types so null lists are flagged at compile time","Wrap enumeration APIs in helpers that allocate the list internally","Initialize collection fields at declaration, not lazily"],"tags":["network","null-argument","argument-validation","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"}