{"record":{"id":"4c3b54fe68806e78","repo":"dotnet/aspnetcore","slug":"invalid-headers","errorCode":null,"errorMessage":"Invalid headers.","messagePattern":"Invalid headers\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts","lineNumber":368,"sourceCode":"        return BinaryMessageFormat.write(payload.slice());\n    }\n\n    private _writeAck(ackMessage: AckMessage): ArrayBuffer {\n        const payload = this._encoder.encode([MessageType.Ack, ackMessage.sequenceId]);\n\n        return BinaryMessageFormat.write(payload.slice());\n    }\n\n    private _writeSequence(sequenceMessage: SequenceMessage): ArrayBuffer {\n        const payload = this._encoder.encode([MessageType.Sequence, sequenceMessage.sequenceId]);\n\n        return BinaryMessageFormat.write(payload.slice());\n    }\n\n    private _readHeaders(properties: any): MessageHeaders {\n        const headers: MessageHeaders = properties[1] as MessageHeaders;\n        if (typeof headers !== \"object\") {\n            throw new Error(\"Invalid headers.\");\n        }\n        return headers;\n    }\n}\n","sourceCodeStart":350,"sourceCodeEnd":373,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts#L350-L373","documentation":"Thrown by _readHeaders when properties[1] (the headers slot) is not of type 'object'. Every header-bearing message (Invocation, StreamItem, Completion) expects its second array element to be a headers object/map (possibly empty {}). This fires when that slot is a string, number, boolean, null, or undefined — i.e. a malformed header field.","triggerScenarios":"Server serializes a message with headers set to null or a string instead of an object; a frame where the headers map was omitted shifting elements; typeof null === 'object' passes, but a string/number headers value triggers it.","commonSituations":"Custom server not emitting the headers map; version mismatch; corruption; a hub method that sets invalid headers via the IHubContext.","solutions":["Ensure the server always emits a headers object (empty {} when none) in the correct array position.","Align SignalR versions.","Catch and reconnect — a malformed header field cannot be auto-repaired.","Inspect server-side code that populates HubMessage.Headers."],"exampleFix":"// before\n// server: msg.Headers = \"x\"  // wrong type\n\n// after\n// server: msg.Headers = new Dictionary<string, string>();  // object/map","handlingStrategy":"validation","validationCode":"// if you decode frames yourself, validate the headers slot is an object\nfunction headersAreValid(decoded: unknown): boolean {\n  return Array.isArray(decoded)\n    && decoded.length >= 2\n    && typeof decoded[1] === 'object'\n    && decoded[1] !== null;\n}","typeGuard":"function isMessageHeaders(v: unknown): v is Record<string, string> {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  const messages = protocol.parseMessages(buffer, logger);\n} catch (e) {\n  if (e.message === 'Invalid headers.') {\n    logger.log(LogLevel.Error, 'Message headers field is not an object; reconnecting.');\n    await connection.start();\n  } else throw e;\n}","preventionTips":["Ensure the server always emits a headers object (empty {} when none) in the correct array position.","Align SignalR versions so the headers slot is consistently positioned.","Catch header-validation failures and reconnect rather than crashing."],"tags":["messagepack","headers","validation","parsing","serialization"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}