{"record":{"id":"842fff606255ff97","repo":"dotnet/aspnetcore","slug":"invalid-input-for-messagepack-hub-protocol-expect","errorCode":null,"errorMessage":"Invalid input for MessagePack hub protocol. Expected an ArrayBuffer.","messagePattern":"Invalid input for MessagePack hub protocol\\. Expected an ArrayBuffer\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts","lineNumber":76,"sourceCode":"            messagePackOptions.extensionCodec,\n            messagePackOptions.context,\n            messagePackOptions.maxStrLength,\n            messagePackOptions.maxBinLength,\n            messagePackOptions.maxArrayLength,\n            messagePackOptions.maxMapLength,\n            messagePackOptions.maxExtLength,\n        );\n    }\n\n    /** Creates an array of HubMessage objects from the specified serialized representation.\n     *\n     * @param {ArrayBuffer} input An ArrayBuffer containing the serialized representation.\n     * @param {ILogger} logger A logger that will be used to log messages that occur during parsing.\n     */\n    public parseMessages(input: ArrayBuffer, logger: ILogger): HubMessage[] {\n        // The interface does allow \"string\" to be passed in, but this implementation does not. So let's throw a useful error.\n        if (!(isArrayBuffer(input))) {\n            throw new Error(\"Invalid input for MessagePack hub protocol. Expected an ArrayBuffer.\");\n        }\n\n        if (logger === null) {\n            logger = NullLogger.instance;\n        }\n\n        const messages = BinaryMessageFormat.parse(input);\n\n        const hubMessages = [];\n        for (const message of messages) {\n            const parsedMessage = this._parseMessage(message, logger);\n            // Can be null for an unknown message. Unknown message is logged in parseMessage\n            if (parsedMessage) {\n                hubMessages.push(parsedMessage);\n            }\n        }\n\n        return hubMessages;","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr-protocol-msgpack/src/MessagePackHubProtocol.ts#L58-L94","documentation":"Thrown by MessagePackHubProtocol.parseMessages if the input is not an ArrayBuffer. The HubProtocol interface nominally allows string, but the MessagePack implementation requires binary; isArrayBuffer(input) returns false for typed arrays, SharedArrayBuffer, ArrayBufferView (e.g. Uint8Array), Node Buffers, or strings.","triggerScenarios":"Calling parseMessages with a Uint8Array, a DataView, a Node.js Buffer, a string, or any ArrayBufferView instead of a true ArrayBuffer. Most commonly hit by code that obtains message bytes from a source that yields a view rather than the underlying buffer.","commonSituations":"Integrating the MessagePack protocol into a custom transport that yields Uint8Array chunks; feeding decrypted/decompressed data held in a Uint8Array; porting code from the JSON protocol where string was acceptable.","solutions":["Pass the underlying ArrayBuffer: use input.buffer where input is a Uint8Array (mind byteOffset/byteLength for subarrays).","Construct a fresh ArrayBuffer copy: new Uint8Array(otherView).buffer is NOT safe if offset≠0; use otherView.slice().buffer instead.","If you have a string, you are using the wrong protocol — use the JsonHubProtocol instead."],"exampleFix":"// before\nprotocol.parseMessages(uint8ArrayFromTransport, logger); // isArrayBuffer=false → throws\n\n// after — hand over the true ArrayBuffer\nconst ab = uint8Array.byteOffset === 0\n  ? uint8Array.buffer\n  : uint8Array.slice().buffer;\nprotocol.parseMessages(ab, logger);","handlingStrategy":"type-guard","validationCode":"function toArrayBuffer(input: ArrayBuffer | ArrayBufferView): ArrayBuffer {\n  if (input instanceof ArrayBuffer) return input;\n  const view = input as ArrayBufferView;\n  if (view.byteOffset === 0 && view.byteLength === view.buffer.byteLength) return view.buffer;\n  return (input as Uint8Array).slice().buffer;\n}\n// usage:\nprotocol.parseMessages(toArrayBuffer(received), logger);","typeGuard":"function isArrayBufferLike(v: unknown): v is ArrayBuffer {\n  return v instanceof ArrayBuffer;\n}","tryCatchPattern":"try {\n  protocol.parseMessages(input as ArrayBuffer, logger);\n} catch (e) {\n  if (/Expected an ArrayBuffer/.test((e as Error).message)) {\n    protocol.parseMessages(toArrayBuffer(input as any), logger);\n  } else throw e;\n}","preventionTips":["Normalize all incoming bytes to ArrayBuffer at the transport boundary.","Use JsonHubProtocol if your data is text.","Never pass Uint8Array/DataView/Node Buffer directly to MessagePackHubProtocol."],"tags":["signalr","messagepack","type-mismatch","arraybuffer","typescript"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}