{"record":{"id":"247aad4e85e791c2","repo":"microsoft/autogen","slug":"unsupported-message-type-m-gettype","errorCode":null,"errorMessage":"Unsupported message type: {m.GetType()}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":220,"sourceCode":"    private IEnumerable<IMessage> ProcessMessage(IEnumerable<IMessage> messages, IAgent agent)\n    {\n        return messages.SelectMany(m =>\n        {\n            if (m is Core.IMessage<Content> messageEnvelope)\n            {\n                return [m];\n            }\n            else\n            {\n                return m switch\n                {\n                    TextMessage textMessage => ProcessTextMessage(textMessage, agent),\n                    ImageMessage imageMessage => ProcessImageMessage(imageMessage, agent),\n                    MultiModalMessage multiModalMessage => ProcessMultiModalMessage(multiModalMessage, agent),\n                    ToolCallMessage toolCallMessage => ProcessToolCallMessage(toolCallMessage, agent),\n                    ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage, agent),\n                    ToolCallAggregateMessage toolCallAggregateMessage => ProcessToolCallAggregateMessage(toolCallAggregateMessage, agent),\n                    _ when strictMode => throw new InvalidOperationException($\"Unsupported message type: {m.GetType()}\"),\n                    _ => [m],\n                };\n            }\n        });\n    }\n\n    private IEnumerable<IMessage> ProcessToolCallAggregateMessage(ToolCallAggregateMessage toolCallAggregateMessage, IAgent agent)\n    {\n        var parseAsUser = ShouldParseAsUser(toolCallAggregateMessage, agent);\n        if (parseAsUser)\n        {\n            var content = toolCallAggregateMessage.GetContent();\n\n            if (content is string str)\n            {\n                var textMessage = new TextMessage(Role.User, str, toolCallAggregateMessage.From);\n\n                return ProcessTextMessage(textMessage, agent);","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L202-L238","documentation":"Thrown by GeminiMessageConnector.ProcessMessage when strictMode is enabled (GeminiMessageConnector strictMode: true) and an incoming IMessage does not match any of the supported message types (TextMessage, ImageMessage, MultiModalMessage, ToolCallMessage, ToolCallResultMessage, ToolCallAggregateMessage, or an IMessage<Content> envelope). Strict mode exists to surface mapping gaps instead of silently passing untranslatable messages to Gemini.","triggerScenarios":"Constructing GeminiMessageConnector with strictMode:true and sending a message whose runtime type is outside the switch — e.g. a custom IMessage subclass, MessageEnvelope wrapping an unexpected payload, or another vendor's message type from a multi-agent pipeline.","commonSituations":"Heterogeneous agent graphs (Gemini agent talking to an LLM/OpenAI agent whose message type leaks through); custom middleware injecting proprietary message classes; strictMode turned on to harden a pipeline that previously relied on the lenient pass-through.","solutions":["Convert foreign/custom messages to TextMessage (or MultiModalMessage) before they reach the Gemini agent.","Use the non-strict constructor (strictMode defaults to false) if passing unknown messages through is acceptable.","Wrap the payload as MessageEnvelope.Create(content) with Gemini Content if you already have Gemini-shaped data.","Log m.GetType() from the exception to find which producer emitted the unsupported type."],"exampleFix":"// before\nvar connector = new GeminiMessageConnector(strictMode: true);\nawait geminiAgent.InitiateChatAsync(otherAgent, nil, new MyCustomMessage(\"hi\"));\n\n// after\nvar text = new TextMessage(Role.User, \"hi\", from: otherAgent.Name);\nawait geminiAgent.SendAsync(text);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsGeminiSupportedMessage(IMessage m) => m is TextMessage or ImageMessage or MultiModalMessage or ToolCallMessage or ToolCallResultMessage or ToolCallAggregateMessage or Core.IMessage<Content>;","tryCatchPattern":null,"preventionTips":["Normalize all messages to TextMessage at group-chat boundaries","Only enable strictMode when you control every producer in the graph","Log message runtime types in tests"],"tags":["gemini","strict-mode","message-mapping","invalid-operation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}