{"record":{"id":"b19abd1b8defdc50","repo":"microsoft/autogen","slug":"unexpected-message-message","errorCode":null,"errorMessage":"Unexpected message '{message}'.","messagePattern":"Unexpected message '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs","lineNumber":487,"sourceCode":"\n    public async ValueTask OnMessageAsync(Message message, CancellationToken cancellation = default)\n    {\n        switch (message.MessageCase)\n        {\n            case Message.MessageOneofCase.Request:\n                var request = message.Request ?? throw new InvalidOperationException(\"Request is null.\");\n                await HandleRequest(request);\n                break;\n            case Message.MessageOneofCase.Response:\n                var response = message.Response ?? throw new InvalidOperationException(\"Response is null.\");\n                await HandleResponse(response);\n                break;\n            case Message.MessageOneofCase.CloudEvent:\n                var cloudEvent = message.CloudEvent ?? throw new InvalidOperationException(\"CloudEvent is null.\");\n                await HandlePublish(cloudEvent);\n                break;\n            default:\n                throw new InvalidOperationException($\"Unexpected message '{message}'.\");\n        }\n    }\n}\n\n","sourceCodeStart":469,"sourceCodeEnd":492,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/Core.Grpc/GrpcAgentRuntime.cs#L469-L492","documentation":"Thrown in OnMessageAsync when the Message oneof case is none of Request, Response, or CloudEvent — most commonly MessageOneofCase.None (an unset message) or a case added in a newer protocol version. The runtime treats any unrecognized shape as a protocol violation.","triggerScenarios":"Sending new Message() with no oneof field set; sending a message whose oneof case exists only in a newer proto (e.g. a new message kind) to an older runtime; deserialization errors that leave the oneof unset.","commonSituations":"Version skew between client SDK and runtime (new message kinds not understood by the old side); accidental dispatch of empty messages; fire-and-forget code paths that construct Message without payload.","solutions":["Ensure every Message sent has exactly one of Request, Response, or CloudEvent set","Align client SDK and runtime versions so both sides understand the same oneof cases","Add a guard before dispatch: skip/log messages with MessageCase == MessageOneofCase.None"],"exampleFix":"// before\nawait router.SendAsync(new Message()); // empty -> throws\n\n// after\nif (msg.MessageCase == Message.MessageOneofCase.None) { /* skip */ }\nelse { await runtime.OnMessageAsync(msg); }","handlingStrategy":"validation","validationCode":"if (msg.MessageCase is not (Message.MessageOneofCase.Request or Message.MessageOneofCase.Response or Message.MessageOneofCase.CloudEvent))\n{\n    _logger.LogWarning(\"Dropping unsupported message case {Case}\", msg.MessageCase);\n    return;\n}","typeGuard":"static bool IsSupported(Message m) => m.MessageCase is Message.MessageOneofCase.Request or Message.MessageOneofCase.Response or Message.MessageOneofCase.CloudEvent;","tryCatchPattern":"try { await runtime.OnMessageAsync(msg); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected message\")) { _logger.LogWarning(ex, \"Unsupported message case\"); }","preventionTips":["Filter MessageCase.None and unknown cases before dispatch","Pin matching SDK/runtime versions to avoid unrecognized oneof cases"],"tags":["grpc","protobuf","oneof","protocol"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}