{"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/ts/signalr/src/JsonHubProtocol.ts#L31-L67","documentation":"After JSON.parse, each framed message must carry a numeric `type` field so the protocol can dispatch it (Invocation=1, StreamItem=2, Completion=3, etc.). When `type` is missing, null, or non-numeric the protocol cannot route the message and rejects the whole batch.","triggerScenarios":"A server (or middleware/proxy) emits a JSON object without a `type` property, or sends `type` as a string like \"1\". Also occurs if a non-SignalR JSON payload reaches the parser, or if message framing splits a JSON object in half.","commonSituations":"Client/server protocol version mismatch, a reverse proxy or CDN rewriting/stripping fields, a hand-rolled server that omits `type`, or corrupted transport data producing a partial JSON object.","solutions":["Confirm client and server run compatible SignalR protocol versions (the TS JSON protocol is version 2).","Inspect the raw framed payload with logMessageContent:true to see the actual JSON and confirm `type` is present and numeric.","Remove any proxy/middleware that alters the response body between server and client.","If building messages manually, always include a numeric `type` from the MessageType enum."],"exampleFix":"// before\nconst bad = '{\"target\":\"Do\"}'; // no type field\n\n// after\nconst ok = '{\"type\":1,\"target\":\"Do\",\"arguments\":[]}';","handlingStrategy":"try-catch","validationCode":"// If you build messages, validate before send\nfunction validHubMessage(m: any): boolean {\n  return typeof m?.type === 'number';\n}","typeGuard":"function isHubMessage(v: any): v is { type: number } {\n  return v != null && typeof v.type === 'number';\n}","tryCatchPattern":"try {\n  hubConnection.start();\n} catch (e) {\n  // protocol-level parse errors usually surface via onclose; inspect raw logs\n  if (e instanceof Error && e.message === 'Invalid payload.') {\n    // enable logMessageContent to capture the offending JSON\n  }\n}","preventionTips":["Keep client and server on compatible SignalR protocol versions.","Enable logMessageContent:true during integration to capture raw frames.","Never inject non-SignalR JSON into the connection pipeline."],"tags":["typescript","signalr","protocol","validation","message-framing"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}