{"record":{"id":"a1700f576ae85432","repo":"dotnet/aspnetcore","slug":"unexpected-message-type-d","errorCode":null,"errorMessage":"Unexpected message type: %d","messagePattern":"Unexpected message type: (.+?)","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":172,"sourceCode":"                    message = writeStreamItemMessage((StreamItem) hubMessage);\n                    break;\n                case COMPLETION:\n                    message = writeCompletionMessage((CompletionMessage) hubMessage);\n                    break;\n                case STREAM_INVOCATION:\n                    message = writeStreamInvocationMessage((StreamInvocationMessage) hubMessage);\n                    break;\n                case CANCEL_INVOCATION:\n                    message = writeCancelInvocationMessage((CancelInvocationMessage) hubMessage);\n                    break;\n                case PING:\n                    message = writePingMessage((PingMessage) hubMessage);\n                    break;\n                case CLOSE:\n                    message = writeCloseMessage((CloseMessage) hubMessage);\n                    break;\n                default:\n                    throw new RuntimeException(String.format(\"Unexpected message type: %d\", messageType.value));\n            }\n            int length = message.length;\n            List<Byte> header = Utils.getLengthHeader(length);\n            byte[] messageWithHeader = new byte[header.size() + length];\n            int headerSize = header.size();\n\n            // Write the length header, then all of the bytes of the original message\n            for (int i = 0; i < headerSize; i++) {\n                messageWithHeader[i] = header.get(i);\n            }\n            for (int i = 0; i < length; i++) {\n                messageWithHeader[i + headerSize] = message[i];\n            }\n\n            return ByteBuffer.wrap(messageWithHeader);\n        } catch (MessagePackException | IOException ex) {\n            throw new RuntimeException(\"Error writing MessagePack data.\", ex);\n        }","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/messagepack/src/main/java/com/microsoft/signalr/messagepack/MessagePackHubProtocol.java#L154-L190","documentation":"writeMessage switches on HubMessageType when serializing outbound and throws for an unrecognized type value. This indicates an internal/library inconsistency — a HubMessage whose getType() returns a value outside INVOCATION/STREAM_ITEM/COMPLETION/STREAM_INVOCATION/CANCEL_INVOCATION/PING/CLOSE.","triggerScenarios":"Constructing or sending a HubMessage whose type is outside the known enum; a custom HubMessage subclass; an enum value added without the writer being updated.","commonSituations":"Custom HubMessage subclass passed to send; library internal bug; mixing incompatible library builds.","solutions":["Only send standard hub message instances produced by the SDK (invoke/send/stream).","Never subclass HubMessage to send custom types.","If it recurs with stock usage, report it with a repro against the official library."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    hubConnection.send(\"Method\").blockingAwait();\n} catch (RuntimeException ex) {\n    if (ex.getMessage() != null && ex.getMessage().contains(\"Unexpected message type\")) {\n    }\n}","preventionTips":["Only send standard HubMessage instances produced by invoke/send/stream.","Never subclass HubMessage to send custom types.","Report recurrence with stock usage to the library maintainers."],"tags":["signalr","messagepack","internal","protocol"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}