{"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":null,"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/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 [MessageType.StreamItem, headers, invocationId, item], so four is the minimum. This fires when a streaming result frame is missing its invocationId or item slot.","triggerScenarios":"Server sends a StreamItem frame missing the item element; corruption strips trailing bytes of a streaming result; the server is an older/newer version using a different StreamItem layout.","commonSituations":"Version mismatch between client and server streaming implementation; a server-side streaming hub method throwing mid-stream producing a malformed frame; network truncation of a large streamed item.","solutions":["Confirm client and server SignalR versions match, especially for streaming scenarios.","Check that server-side streaming methods (IAsyncEnumerable / Channel) complete cleanly.","Catch the error and end the affected stream subscription / reconnect.","Inspect the failing hub method for exceptions during enumeration."],"exampleFix":"// before\nconnection.stream('StreamData').subscribe({ next: x => {} });\n// server emits short StreamItem -> throws inside parseMessages\n\n// after\nconnection.stream('StreamData').subscribe({\n  next: x => {},\n  error: err => logger.log(LogLevel.Error, 'Stream failed: ' + err),\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const subscription = connection.stream('StreamData').subscribe({\n  next: x => handleItem(x),\n  error: err => {\n    if (/StreamItem message/.test(err?.message)) {\n      logger.log(LogLevel.Error, 'Malformed StreamItem; resubscribing.');\n      reconnect();\n    }\n  },\n});","preventionTips":["Always provide an error handler to connection.stream(...).subscribe().","Keep streaming implementations on both ends at compatible SignalR versions.","Ensure server-side streaming methods (Channel / IAsyncEnumerable) don't throw mid-enumeration producing malformed frames."],"tags":["messagepack","streaming","streamitem","validation","parsing"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}