dotnet/aspnetcore · error · RuntimeException

Error reading MessagePack data.

Error message

Error reading MessagePack data.

What it means

Wraps MessagePackException or IOException thrown while unpacking the message body (array headers, strings, typed values). It is the generic catch-all for malformed binary content during decode, raised from the try block wrapping the MessageUnpacker usage.

Source

Thrown at src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java:137

                // Make sure that we actually read the right number of bytes
                int readBytes = (int) unpacker.getTotalReadBytes();
                if (readBytes != length) {
                    // Check what the last message was
                    // If it was an invocation binding failure, we have to correct the position of the buffer
                    if (hubMessages.get(hubMessages.size() - 1).getMessageType() == HubMessageType.INVOCATION_BINDING_FAILURE) {
                        // Cast to a Buffer to avoid the Java 9+ behavior where ByteBuffer.position(int) overrides Buffer.position(int),
                        // Returning a ByteBuffer rather than a Buffer. This causes issues on Android - see https://github.com/dotnet/aspnetcore/pull/26614
                        ((Buffer) payload).position(payload.position() + (length - readBytes));
                    } else {
                        throw new RuntimeException(String.format("MessagePack message was length %d but claimed to be length %d.", readBytes, length));
                    }
                }
                unpacker.close();
                // Cast to a Buffer to avoid the Java 9+ behavior where ByteBuffer.position(int) overrides Buffer.position(int),
                // Returning a ByteBuffer rather than a Buffer. This causes issues on Android - see https://github.com/dotnet/aspnetcore/pull/26614
                ((Buffer) payload).position(payload.position() + readBytes);
            } catch (MessagePackException | IOException ex) {
                throw new RuntimeException("Error reading MessagePack data.", ex);
            }
        }
        return hubMessages;
    }

    @Override
    public ByteBuffer writeMessage(HubMessage hubMessage) {
        HubMessageType messageType = hubMessage.getMessageType();

        try {
            byte[] message;
            switch (messageType) {
                case INVOCATION:
                    message = writeInvocationMessage((InvocationMessage) hubMessage);
                    break;
                case STREAM_ITEM:
                    message = writeStreamItemMessage((StreamItem) hubMessage);
                    break;

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Confirm both sides negotiated the messagepack protocol.
  2. Update both client and server to matching SignalR versions.
  3. Capture the wire bytes to validate framing and content.
Defensive patterns

Strategy: try-catch

Try / catch

// Java
hubConnection.start().subscribe(ok -> {}, err -> {
    if (err.getMessage() != null && err.getMessage().contains("reading MessagePack")) {
        // confirm both sides use messagepack and matching versions
    }
});

Prevention

When it happens

Trigger: Malformed MessagePack bytes; an unexpected value type for a field; stream corruption mid-message; peer sending non-MessagePack data on a MessagePack connection.

Common situations: Mismatched protocol versions; truncated frames; a JSON-protocol server paired with a MessagePack client; corrupt buffer offsets.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/fe35e90eda2cc287. Report an issue: GitHub.