{"record":{"id":"cfe74a125a577e10","repo":"dotnet/aspnetcore","slug":"invalid-payload-for-streamitem-message-cfe74a","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/src/JsonHubProtocol.ts","lineNumber":105,"sourceCode":"     * @returns {string} A string containing the serialized representation of the message.\n     */\n    public writeMessage(message: HubMessage): string {\n        return TextMessageFormat.write(JSON.stringify(message));\n    }\n\n    private _isInvocationMessage(message: InvocationMessage): void {\n        this._assertNotEmptyString(message.target, \"Invalid payload for Invocation message.\");\n\n        if (message.invocationId !== undefined) {\n            this._assertNotEmptyString(message.invocationId, \"Invalid payload for Invocation message.\");\n        }\n    }\n\n    private _isStreamItemMessage(message: StreamItemMessage): void {\n        this._assertNotEmptyString(message.invocationId, \"Invalid payload for StreamItem message.\");\n\n        if (message.item === undefined) {\n            throw new Error(\"Invalid payload for StreamItem message.\");\n        }\n    }\n\n    private _isCompletionMessage(message: CompletionMessage): void {\n        if (message.result && message.error) {\n            throw new Error(\"Invalid payload for Completion message.\");\n        }\n\n        if (!message.result && message.error) {\n            this._assertNotEmptyString(message.error, \"Invalid payload for Completion message.\");\n        }\n\n        this._assertNotEmptyString(message.invocationId, \"Invalid payload for Completion message.\");\n    }\n\n    private _isAckMessage(message: AckMessage): void {\n        if (typeof message.sequenceId !== 'number') {\n            throw new Error(\"Invalid SequenceId for Ack message.\");","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/JsonHubProtocol.ts#L87-L123","documentation":"Thrown by JsonHubProtocol._isStreamItemMessage when a StreamItem message has an undefined `item` field. The validator already checks invocationId via _assertNotEmptyString; reaching the second throw means the invocationId passed but the payload carries no streamed item, which is meaningless for a StreamItem.","triggerScenarios":"Server (or a malformed/injected frame) sends a JSON message with `type: 2` (StreamItem), a valid invocationId, but `item` is omitted/null. The client refuses to surface an empty stream item.","commonSituations":"Server-side hub method yields undefined for a streaming result, a serializer strips null-valued properties, or a custom server implementation that does not populate `item`.","solutions":["On the server, ensure streaming methods yield concrete values (or a sentinel) rather than undefined.","Configure the serializer to include null fields if item may legitimately be null.","Verify the hub method return type is IEnumerable/IAsyncEnumerable<T> with a non-null T."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function validStreamItem(m: any): boolean {\n  return typeof m.invocationId === \"string\" && m.invocationId !== \"\" && m.item !== undefined;\n}","typeGuard":"function isCompleteStreamItem(m: any): boolean {\n  return typeof m?.invocationId === \"string\" && m.invocationId.length > 0 && m.item !== undefined;\n}","tryCatchPattern":null,"preventionTips":["Ensure streaming hub methods yield non-undefined values.","Configure the serializer to preserve null fields where needed.","Use a non-null element type for IAsyncEnumerable<T>."],"tags":["protocol","json","streaming","parsing"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}