{"record":{"id":"0b73b144e23012a1","repo":"dotnet/aspnetcore","slug":"invalid-payload-0b73b1","errorCode":null,"errorMessage":"Invalid payload.","messagePattern":"Invalid payload\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/JsonHubProtocol.ts","lineNumber":49,"sourceCode":"            throw new Error(\"Invalid input for JSON hub protocol. Expected a string.\");\n        }\n\n        if (!input) {\n            return [];\n        }\n\n        if (logger === null) {\n            logger = NullLogger.instance;\n        }\n\n        // Parse the messages\n        const messages = TextMessageFormat.parse(input);\n\n        const hubMessages = [];\n        for (const message of messages) {\n            const parsedMessage = JSON.parse(message) as HubMessage;\n            if (typeof parsedMessage.type !== \"number\") {\n                throw new Error(\"Invalid payload.\");\n            }\n            switch (parsedMessage.type) {\n                case MessageType.Invocation:\n                    this._isInvocationMessage(parsedMessage);\n                    break;\n                case MessageType.StreamItem:\n                    this._isStreamItemMessage(parsedMessage);\n                    break;\n                case MessageType.Completion:\n                    this._isCompletionMessage(parsedMessage);\n                    break;\n                case MessageType.Ping:\n                    // Single value, no need to validate\n                    break;\n                case MessageType.Close:\n                    // All optional values, no need to validate\n                    break;\n                case MessageType.Ack:","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/JsonHubProtocol.ts#L31-L67","documentation":"Thrown by JsonHubProtocol's message-type switch when `parsedMessage.type` is not a `number`. After JSON.parse, every hub message must carry a numeric `type` discriminator (Invocation=1, StreamItem=2, Completion=3, StreamInvocation=4, CancelInvocation=5, Ping=6, Close=7, Ack=8, Sequence=9, etc.); a missing or non-numeric type cannot be dispatched and is rejected as an invalid payload.","triggerScenarios":"Receiving a JSON message that omits the `type` field, sets it to a string, or carries an out-of-range value that does not match any MessageType case (the throw fires before the switch handles known types because the type check happens up front).","commonSituations":"Interoperating with a hand-rolled/older server that omits `type`, a malformed proxy rewriting the payload, or a protocol-version mismatch (e.g. server speaks an older JSON protocol without type field).","solutions":["Verify the server and client use the same SignalR JSON protocol version.","Inspect the raw frame to confirm each message object includes a numeric `type`.","If proxying/transforming frames, preserve the `type` field unchanged."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"function hasNumericType(m: any): boolean {\n  return m && typeof m.type === \"number\";\n}","typeGuard":"function isTypedHubMessage(m: any): m is { type: number } {\n  return !!m && typeof m.type === \"number\";\n}","tryCatchPattern":null,"preventionTips":["Keep client and server on the same SignalR protocol version.","Preserve the type field through any proxy/transform.","Validate frames at integration boundaries."],"tags":["protocol","json","parsing","message-type"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}