{"record":{"id":"97a24669f9422bef","repo":"dotnet/aspnetcore","slug":"invalid-payload-for-streamitem-message","errorCode":null,"errorMessage":"Invalid payload for StreamItem message.","messagePattern":"Invalid payload for StreamItem message\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts","lineNumber":218,"sourceCode":"                target: properties[3] as string,\n                type: MessageType.Invocation,\n            };\n        } else {\n            return {\n                arguments: properties[4],\n                headers,\n                streamIds: [],\n                target: properties[3],\n                type: MessageType.Invocation,\n            };\n        }\n\n    }\n\n    private _createStreamItemMessage(headers: MessageHeaders, properties: any[]): StreamItemMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 4) {\n            throw new Error(\"Invalid payload for StreamItem message.\");\n        }\n\n        return {\n            headers,\n            invocationId: properties[2],\n            item: properties[3],\n            type: MessageType.StreamItem,\n        } as StreamItemMessage;\n    }\n\n    private _createCompletionMessage(headers: MessageHeaders, properties: any[]): CompletionMessage {\n        // check minimum length to allow protocol to add items to the end of objects in future releases\n        if (properties.length < 4) {\n            throw new Error(\"Invalid payload for Completion message.\");\n        }\n\n        const resultKind = properties[3];\n","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts#L200-L236","documentation":"Thrown by _createStreamItemMessage when the decoded properties array has fewer than 4 elements. A StreamItem is encoded as [MessageType.StreamItem, headers, invocationId, item]. Fewer than 4 means the item slot — the actual streamed value — is missing.","triggerScenarios":"Receiving a StreamItem frame missing the item slot; corrupt bytes decoded to a short array typed as StreamItem; a non-conforming server-side streaming implementation.","commonSituations":"Server-side streaming bug that emits the headers/id without the item; protocol version drift; wire corruption mid-stream.","solutions":["Confirm the server's streaming hub method emits items correctly with the canonical MessagePack encoder.","Match server and client SignalR protocol versions.","Reconnect: a malformed stream item invalidates the stream and likely the connection."],"exampleFix":"// before\n// server stream emits [2, {}, '42'] — missing item → throws\n\n// after — server must emit [2, {}, '42', itemValue]","handlingStrategy":"validation","validationCode":"function isValidStreamItemProperties(p: unknown[]): boolean {\n  return p.length >= 4;\n}","typeGuard":"function isStreamItemPayload(p: unknown[]): p is [number, unknown, string, unknown] {\n  return p.length >= 4;\n}","tryCatchPattern":"try { return protocol.parseMessages(buf, logger); }\ncatch (e) {\n  if (/Invalid payload for StreamItem/.test((e as Error).message)) {\n    logger.log(LogLevel.Error, 'Malformed StreamItem — reconnecting');\n    await connection.stop(); await connection.start();\n  } else throw e;\n}","preventionTips":["Confirm the server's streaming implementation emits the item slot.","Match SignalR protocol versions.","Reconnect on stream-item corruption."],"tags":["signalr","messagepack","streaming","streamitem","validation"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}