{"record":{"id":"fe35e90eda2cc287","repo":"dotnet/aspnetcore","slug":"error-reading-messagepack-data","errorCode":null,"errorMessage":"Error reading MessagePack data.","messagePattern":"Error reading MessagePack data\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java","lineNumber":137,"sourceCode":"                // Make sure that we actually read the right number of bytes\n                int readBytes = (int) unpacker.getTotalReadBytes();\n                if (readBytes != length) {\n                    // Check what the last message was\n                    // If it was an invocation binding failure, we have to correct the position of the buffer\n                    if (hubMessages.get(hubMessages.size() - 1).getMessageType() == HubMessageType.INVOCATION_BINDING_FAILURE) {\n                        // Cast to a Buffer to avoid the Java 9+ behavior where ByteBuffer.position(int) overrides Buffer.position(int),\n                        // Returning a ByteBuffer rather than a Buffer. This causes issues on Android - see https://github.com/dotnet/aspnetcore/pull/26614\n                        ((Buffer) payload).position(payload.position() + (length - readBytes));\n                    } else {\n                        throw new RuntimeException(String.format(\"MessagePack message was length %d but claimed to be length %d.\", readBytes, length));\n                    }\n                }\n                unpacker.close();\n                // Cast to a Buffer to avoid the Java 9+ behavior where ByteBuffer.position(int) overrides Buffer.position(int),\n                // Returning a ByteBuffer rather than a Buffer. This causes issues on Android - see https://github.com/dotnet/aspnetcore/pull/26614\n                ((Buffer) payload).position(payload.position() + readBytes);\n            } catch (MessagePackException | IOException ex) {\n                throw new RuntimeException(\"Error reading MessagePack data.\", ex);\n            }\n        }\n        return hubMessages;\n    }\n\n    @Override\n    public ByteBuffer writeMessage(HubMessage hubMessage) {\n        HubMessageType messageType = hubMessage.getMessageType();\n\n        try {\n            byte[] message;\n            switch (messageType) {\n                case INVOCATION:\n                    message = writeInvocationMessage((InvocationMessage) hubMessage);\n                    break;\n                case STREAM_ITEM:\n                    message = writeStreamItemMessage((StreamItem) hubMessage);\n                    break;","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/92f07e298d5c5a629385b8b0a32d7164b1b53906/src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java#L119-L155","documentation":"Thrown by MessagePackHubProtocol.parseMessages (MessagePackHubProtocol.java:137) as the catch-all around the try-with-resources MessageUnpacker block: it catches MessagePackException or IOException raised while unpacking the array header, message type, or any field of an incoming MessagePack frame, and wraps the cause. It signals the bytes are not valid MessagePack (or not valid for the expected hub message shape).","triggerScenarios":"Any MessagePack decoding failure inside the unpacker block: invalid msgpack bytes, wrong type (e.g. unpackString on an int), truncated value, or an IOException during payload reads. Triggered during createInvocationMessage/createStreamItemMessage/createCompletionMessage/etc.","commonSituations":"Corrupt incoming bytes; a server/client MessagePack format mismatch; a custom argument type the unpacker cannot read; a frame that was partially overwritten; transport delivering garbage (e.g. an HTML error page slipped into the binary stream).","solutions":["Inspect the wrapped MessagePackException/IOException cause for the exact field and offset that failed.","Verify the wire bytes are genuinely MessagePack and that client/server protocol versions match.","Ensure server-side argument types are serializable types the client can decode (avoid extension types — see error 197).","Reconnect; persistent decode failures usually indicate a version/format mismatch that needs an upgrade."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"hubConnection.onClosed(ex -> {\n    if (ex != null && ex.getMessage() != null\n        && ex.getMessage().equals(\"Error reading MessagePack data.\")) {\n        // inspect ex.getCause() (MessagePackException/IOException)\n        scheduleReconnect();\n    }\n});","preventionTips":["Ensure server argument types decode cleanly as MessagePack (avoid extension types).","Match client/server SignalR protocol versions.","Reconnect on persistent decode failures; capture the wrapped cause for diagnosis."],"tags":["signalr","java","messagepack","protocol","serialization","io"],"analyzedSha":"92f07e298d5c5a629385b8b0a32d7164b1b53906","analyzedAt":"2026-08-07T06:05:17.747Z","schemaVersion":2},"datasetVersion":"2026-08-07T15:17:06.553Z"}