{"record":{"id":"c1f5c61020de1290","repo":"EllanJiang/GameFramework","slug":"packet-header-is-invalid","errorCode":null,"errorMessage":"Packet header is invalid.","messagePattern":"Packet header is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Network/NetworkManager.NetworkChannelBase.cs","lineNumber":568,"sourceCode":"                {\n                    object customErrorData = null;\n                    IPacketHeader packetHeader = m_NetworkChannelHelper.DeserializePacketHeader(m_ReceiveState.Stream, out customErrorData);\n\n                    if (customErrorData != null && NetworkChannelCustomError != null)\n                    {\n                        NetworkChannelCustomError(this, customErrorData);\n                    }\n\n                    if (packetHeader == null)\n                    {\n                        string errorMessage = \"Packet header is invalid.\";\n                        if (NetworkChannelError != null)\n                        {\n                            NetworkChannelError(this, NetworkErrorCode.DeserializePacketHeaderError, SocketError.Success, errorMessage);\n                            return false;\n                        }\n\n                        throw new GameFrameworkException(errorMessage);\n                    }\n\n                    m_ReceiveState.PrepareForPacket(packetHeader);\n                    if (packetHeader.PacketLength <= 0)\n                    {\n                        bool processSuccess = ProcessPacket();\n                        m_ReceivedPacketCount++;\n                        return processSuccess;\n                    }\n                }\n                catch (Exception exception)\n                {\n                    m_Active = false;\n                    if (NetworkChannelError != null)\n                    {\n                        SocketException socketException = exception as SocketException;\n                        NetworkChannelError(this, NetworkErrorCode.DeserializePacketHeaderError, socketException != null ? socketException.SocketErrorCode : SocketError.Success, exception.ToString());\n                        return false;","sourceCodeStart":550,"sourceCodeEnd":586,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Network/NetworkManager.NetworkChannelBase.cs#L550-L586","documentation":"ProcessPacketHeader asks the INetworkChannelHelper's DeserializePacketHeader to build an IPacketHeader from received bytes. If that fails (or returns null semantics) the channel throws GameFrameworkException (or fires NetworkChannelError with NetworkErrorCode.DeserializePacketHeaderError). The received header bytes could not be parsed into a valid packet header.","triggerScenarios":"Received bytes not matching the expected header format (wrong packet length fields, corrupted stream); server and client using different header protocols; the helper's DeserializePacketHeader returning null/false on malformed input.","commonSituations":"Client talking to a server built with a different protocol version; byte-order (endianness) or header-size mismatch between custom helpers; data corruption or a proxy/intermediary mangling the stream.","solutions":["Verify client and server use the identical packet header layout (field order, sizes, endianness).","Fix/robustify DeserializePacketHeader in your INetworkChannelHelper to validate bytes before parsing.","Check the header handler class registered with the NetworkChannel matches the server protocol version.","Register NetworkChannelError for NetworkErrorCode.DeserializePacketHeaderError and close/reconnect the channel on failure."],"exampleFix":"// before\n// server uses 4-byte length, client helper reads 2-byte length\n// after\nint packetLength = BitConverter.ToInt32(headerBytes, 0); // match server layout","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"networkManager.NetworkChannelError += (channel, code, socketError, msg) => { if (code == NetworkErrorCode.DeserializePacketHeaderError) { channel.Close(); ReconnectLater(); } };","preventionTips":["Keep client and server packet header layouts byte-identical","Version your protocol and negotiate the version on connect","Test header parsing against real server captures","Treat a header deserialization failure as fatal to the stream (connection is desynced); always reconnect"],"tags":["network","deserialization","protocol-mismatch","gameframework"],"backgroundTag":"unexpected-response-shape","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"}