{"record":{"id":"fb5baa359e7e5db6","repo":"microsoft/autogen","slug":"only-textcontent-and-imagecontent-are-allowed-in-m","errorCode":null,"errorMessage":"Only TextContent and ImageContent are allowed in MultiModalMessage","messagePattern":"Only TextContent and ImageContent are allowed in MultiModalMessage","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs","lineNumber":141,"sourceCode":"    /// </summary>\n    /// <param name=\"item\">The <see cref=\"AIContent\"/> to wrap.</param>\n    /// <returns>A <see cref=\"MultiModalData\"/> instance wrapping the <paramref name=\"item\"/>.</returns>\n    /// <exception cref=\"ArgumentException\">\n    /// Thrown if the <paramref name=\"item\"/> is not a <see cref=\"TextContent\"/> or <see cref=\"DataContent\"/>.\n    /// </exception>\n    public static MultiModalData CheckTypeAndCreate(AIContent item)\n    {\n        if (item is TextContent text)\n        {\n            return new MultiModalData(text);\n        }\n        else if (item is DataContent image)\n        {\n            return new MultiModalData(image);\n        }\n        else\n        {\n            throw new ArgumentException(\"Only TextContent and ImageContent are allowed in MultiModalMessage\");\n        }\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"MultiModalData\"/> with a <see cref=\"string\"/>.\n    /// </summary>\n    /// <param name=\"text\">The text to wrap.</param>\n    public MultiModalData(string text)\n    {\n        ContentType = Type.String;\n        AIContent = new TextContent(text);\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"MultiModalData\"/> with a <see cref=\"TextContent\"/>.\n    /// </summary>\n    /// <param name=\"textContent\">The <see cref=\"TextContent\"/> to wrap.</param>\n    public MultiModalData(TextContent textContent)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs#L123-L159","documentation":"MultiModalData.CheckTypeAndCreate only accepts TextContent and DataContent (the message text says 'ImageContent' but the code checks DataContent, which covers image/data URLs). Passing any other AIContent subclass (AudioContent, ErrorContent, UsageContent, custom derivations) into a MultiModalMessage throws ArgumentException because multi-modal messages in this API support only text and data parts.","triggerScenarios":"Constructing MultiModalMessage with items that are not TextContent or DataContent, or calling MultiModalData.CheckTypeAndCreate(item) directly with e.g. an AudioContent from a voice pipeline.","commonSituations":"Upgrading code from an older API where messages held arbitrary AIContent; mixing Microsoft.Extensions.AI content types (audio, tool calls, usage) into a multi-modal payload; custom AIContent subclasses for provider-specific payloads.","solutions":["Restrict MultiModalMessage content to TextContent and DataContent items; carry audio/tool/usage data outside the multi-modal message","Convert unsupported items to text first (e.g. AudioContent -> TextContent transcript or placeholder) if the modality must be flattened","For custom content types, restructure so provider-specific data lives in a different field/type, not in MultiModalMessage"],"exampleFix":"// before\nvar items = new List<AIContent> { new TextContent(\"listen\"), new AudioContent(bytes, \"audio/wav\") };\nvar msg = new MultiModalMessage(items);\n// after\nvar items = new List<AIContent> { new TextContent(\"listen\"), new DataContent(new Uri(\"data:audio/wav;base64,...\")) };\n// or keep only text and handle audio separately","handlingStrategy":"type-guard","validationCode":"var valid = items.All(i => i is TextContent or DataContent);\nif (!valid) throw new ArgumentException(\"MultiModalMessage only accepts TextContent and DataContent items\");\nvar msg = new MultiModalMessage(items);","typeGuard":"static bool IsMultiModalSupported(AIContent content) => content is TextContent or DataContent;","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"Only TextContent and ImageContent\")) { // downgrade: convert item to TextContent or route it outside the multimodal message }","preventionTips":["Filter chat content to TextContent/DataContent before building MultiModalMessage","Keep audio/tool-call/usage content in dedicated fields rather than multi-modal payloads","Write a small mapping layer that converts unsupported AIContent to text before construction"],"tags":["autogen","multimodal","content-type","validation","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}