{"record":{"id":"e5e8b192990a55cc","repo":"microsoft/autogen","slug":"unsupported-message-type-message-gettype","errorCode":null,"errorMessage":"Unsupported message type: {message.GetType()}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":358,"sourceCode":"        return [MessageEnvelope.Create(content, toolCallMessage.From)];\n    }\n\n    private IEnumerable<IMessage> ProcessMultiModalMessage(MultiModalMessage multiModalMessage, IAgent agent)\n    {\n        var parts = new List<Part>();\n        foreach (var message in multiModalMessage.Content)\n        {\n            if (message is TextMessage textMessage)\n            {\n                parts.Add(new Part { Text = textMessage.Content });\n            }\n            else if (message is ImageMessage imageMessage)\n            {\n                parts.Add(CreateImagePart(imageMessage));\n            }\n            else\n            {\n                throw new InvalidOperationException($\"Unsupported message type: {message.GetType()}\");\n            }\n        }\n\n        var shouldParseAsUser = ShouldParseAsUser(multiModalMessage, agent);\n\n        if (strictMode && !shouldParseAsUser)\n        {\n            // image message is not supported as model role in Gemini\n            throw new InvalidOperationException(\"Image message is not supported as model role in Gemini.\");\n        }\n\n        var content = new Content\n        {\n            Parts = { parts },\n            Role = shouldParseAsUser ? \"user\" : \"model\",\n        };\n\n        return [MessageEnvelope.Create(content, multiModalMessage.From)];","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L340-L376","documentation":"GeminiMessageConnector.ProcessMultiModalMessage only knows how to map two content types inside a MultiModalMessage: TextMessage -> Part.Text and ImageMessage -> inline image part. Any other IMessage inside multiModalMessage.Content throws this InvalidOperationException naming the offending type.","triggerScenarios":"Building a MultiModalMessage whose Content collection includes something other than TextMessage/ImageMessage — e.g. an AudioMessage, another MultiModalMessage, or a custom message class.","commonSituations":"Migrating multimodal pipelines that previously targeted OpenAI/GPT-4V connectors with richer content types; adding new modalities (audio, video) without a corresponding connector mapping.","solutions":["Reduce MultiModalMessage content to TextMessage + ImageMessage only before sending to a Gemini agent.","Serialize non-supported modalities to text descriptions, or extend the connector with your own middleware that maps the extra type to a Gemini Part.","Check the exception's type name to find which content item leaked in."],"exampleFix":"// before\nvar mm = new MultiModalMessage(Role.User, [text, image, new AudioMessage(...)], from: \"user\");\n\n// after\nvar mm = new MultiModalMessage(Role.User, [text, image], from: \"user\");","handlingStrategy":"type-guard","validationCode":"var unsupported = multiModalMessage.Content.Where(c => c is not TextMessage and not ImageMessage).ToList();\nif (unsupported.Count > 0) { /* remove or convert items before sending */ }","typeGuard":"static bool IsGeminiMultimodalContent(IEnumerable<IMessage> content) => content.All(m => m is TextMessage or ImageMessage);","tryCatchPattern":null,"preventionTips":["Standardize multimodal payloads to text+image across providers","Write unit tests asserting content composition before sends"],"tags":["gemini","multimodal","message-mapping","invalid-operation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}