{"record":{"id":"1230ff70a26806c9","repo":"microsoft/autogen","slug":"unsupported-message-type-item-gettype-name","errorCode":null,"errorMessage":"Unsupported message type: {item.GetType().Name}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs","lineNumber":220,"sourceCode":"        throw new System.InvalidOperationException(\"MultiModalMessage is not supported in the semantic kernel if it's from self.\");\n    }\n\n    private IEnumerable<ChatMessageContent> ProcessMessageForOthers(MultiModalMessage message)\n    {\n        var collections = new ChatMessageContentItemCollection();\n        foreach (var item in message.Content)\n        {\n            if (item is TextMessage textContent)\n            {\n                collections.Add(new TextContent(textContent.Content));\n            }\n            else if (item is ImageMessage imageContent)\n            {\n                collections.Add(new ImageContent(new Uri(imageContent.Url ?? imageContent.BuildDataUri())));\n            }\n            else\n            {\n                throw new InvalidOperationException($\"Unsupported message type: {item.GetType().Name}\");\n            }\n        }\n        return [new ChatMessageContent(AuthorRole.User, collections)];\n    }\n\n    [Obsolete(\"This method is deprecated, please use the specific method instead.\")]\n    private IEnumerable<ChatMessageContent> ProcessMessageForSelf(Message message)\n    {\n        if (message.Role == Role.System)\n        {\n            return [new ChatMessageContent(AuthorRole.System, message.Content)];\n        }\n        else if (message.Content is string && message.FunctionName is null && message.FunctionArguments is null)\n        {\n            return [new ChatMessageContent(AuthorRole.Assistant, message.Content)];\n        }\n        else if (message.Content is null && message.FunctionName is not null && message.FunctionArguments is not null)\n        {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs#L202-L238","documentation":"ProcessMessageForOthers(MultiModalMessage) flattens each item of the multimodal collection into SK content: TextMessage becomes TextContent, ImageMessage becomes ImageContent. Any other IMessage inside the collection throws InvalidOperationException naming the type.","triggerScenarios":"Building MultiModalMessage.Content with items other than TextMessage/ImageMessage (e.g. ToolCallMessage or a custom message) and sending it to an SK agent.","commonSituations":"Generically mapping a mixed message list into multimodal content; adding new message kinds to an existing multimodal builder without updating consumers.","solutions":["Construct MultiModalMessage with only TextMessage and ImageMessage items.","Project/flatten other message types into text (stringify JSON) before adding them to the collection.","Add a validation pass over multimodal content at build time (see defense section) to fail early with context."],"exampleFix":"// before\nvar content = new IMessage[] { new TextMessage(Role.User, \"hi\"), toolCallResult };\nvar mm = new MultiModalMessage(Role.User, content);\n\n// after\nvar content = new IMessage[] { new TextMessage(Role.User, \"hi\"), new TextMessage(Role.User, toolCallResult.ToString()) };\nvar mm = new MultiModalMessage(Role.User, content);","handlingStrategy":"type-guard","validationCode":"if (multiModal.Content.Any(i => i is not (TextMessage or ImageMessage)))\n    throw new ArgumentException(\"MultiModalMessage items for SK must be TextMessage or ImageMessage.\");","typeGuard":"static bool IsValidSkMultimodalContent(IEnumerable<IMessage> items) =>\n    items.All(i => i is TextMessage or ImageMessage);","tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Unsupported message type:\"))\n{\n    logger.LogError(\"Bad multimodal item: {Message}\", ex.Message);\n    throw;\n}","preventionTips":["Build multimodal messages through one factory that only accepts text and image items.","Serialize any structured payload into a TextMessage before adding it to multimodal content."],"tags":["semantic-kernel","multimodal","message-connector","autogen","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}