{"record":{"id":"49d8264d71553ac9","repo":"EllanJiang/GameFramework","slug":"packet-is-invalid","errorCode":null,"errorMessage":"Packet is invalid.","messagePattern":"Packet is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Network/NetworkManager.NetworkChannelBase.cs","lineNumber":454,"sourceCode":"                    if (NetworkChannelError != null)\n                    {\n                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                if (packet == null)\n                {\n                    string errorMessage = \"Packet is invalid.\";\n                    if (NetworkChannelError != null)\n                    {\n                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                lock (m_SendPacketPool)\n                {\n                    m_SendPacketPool.Enqueue(packet);\n                }\n            }\n\n            /// <summary>\n            /// 释放资源。\n            /// </summary>\n            public void Dispose()\n            {\n                Dispose(true);\n                GC.SuppressFinalize(this);\n            }\n\n            /// <summary>","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Network/NetworkManager.NetworkChannelBase.cs#L436-L472","documentation":"Send<T> requires a non-null packet instance of a Packet-derived type. Passing null is rejected with GameFrameworkException (or NetworkChannelError with NetworkErrorCode.SendError). The packet is only enqueued here; serialization happens later in ProcessSend.","triggerScenarios":"Calling channel.Send<T>(null); passing the result of a factory/deserialize call that returned null; a variable typed Packet that was never assigned.","commonSituations":"Building packets from data that failed to load (null result); generic send helpers that forward possibly-null references; refactors that changed packet construction and silently produce null.","solutions":["Null-check the packet before calling Send and log/return instead.","Fix the packet construction code so it never returns null (throw at the factory instead).","Register NetworkChannelError to convert the exception into an event-driven SendError.","In generic send wrappers, add a where T : Packet, class constraint plus a null assertion."],"exampleFix":"// before\nchannel.Send(BuildPacket()); // BuildPacket may return null\n// after\nvar packet = BuildPacket();\nif (packet != null) { channel.Send(packet); }","handlingStrategy":"validation","validationCode":"if (packet is null) throw new ArgumentNullException(nameof(packet)); channel.Send(packet);","typeGuard":"public static bool IsValidPacket(Packet p) => p != null;","tryCatchPattern":"try { channel.Send(packet); } catch (GameFrameworkException ex) when (ex.Message == \"Packet is invalid.\") { LogSendFailure(packet); }","preventionTips":["Null-check packet factories' return values","Use nullable reference types (Packet?) to catch null flow at compile time","Never pass the result of a fallible deserialize directly to Send","Assert non-null in generic send helpers"],"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-15T23:17:13.987Z"}