dotnet/aspnetcore · error · Error
Invalid payload for StreamItem message.
Error message
Invalid payload for StreamItem message.
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
function validStreamItem(m: any): boolean {
return typeof m.invocationId === "string" && m.invocationId !== "" && m.item !== undefined;
} Type guard
function isCompleteStreamItem(m: any): boolean {
return typeof m?.invocationId === "string" && m.invocationId.length > 0 && m.item !== undefined;
} Prevention
- 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>.
When it happens
Trigger: 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.
Common situations: 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`.
Related errors
- Error reading JSON.
- errorMessage
- Invalid input for JSON hub protocol. Expected a string.
- Invalid payload.
- Invalid payload for Completion message.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/cfe74a125a577e10.
Report an issue: GitHub.
Appendix: source
Thrown at src/SignalR/clients/ts/signalr/src/JsonHubProtocol.ts:105
* @returns {string} A string containing the serialized representation of the message.
*/
public writeMessage(message: HubMessage): string {
return TextMessageFormat.write(JSON.stringify(message));
}
private _isInvocationMessage(message: InvocationMessage): void {
this._assertNotEmptyString(message.target, "Invalid payload for Invocation message.");
if (message.invocationId !== undefined) {
this._assertNotEmptyString(message.invocationId, "Invalid payload for Invocation message.");
}
}
private _isStreamItemMessage(message: StreamItemMessage): void {
this._assertNotEmptyString(message.invocationId, "Invalid payload for StreamItem message.");
if (message.item === undefined) {
throw new Error("Invalid payload for StreamItem message.");
}
}
private _isCompletionMessage(message: CompletionMessage): void {
if (message.result && message.error) {
throw new Error("Invalid payload for Completion message.");
}
if (!message.result && message.error) {
this._assertNotEmptyString(message.error, "Invalid payload for Completion message.");
}
this._assertNotEmptyString(message.invocationId, "Invalid payload for Completion message.");
}
private _isAckMessage(message: AckMessage): void {
if (typeof message.sequenceId !== 'number') {
throw new Error("Invalid SequenceId for Ack message.");View on GitHub (pinned to 3600ca084e)