microsoft/autogen · error · ArgumentException
Only TextContent and ImageContent are allowed in MultiModalM
Error message
Only TextContent and ImageContent are allowed in MultiModalMessage
What it means
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.
Source
Thrown at dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs:141
/// </summary>
/// <param name="item">The <see cref="AIContent"/> to wrap.</param>
/// <returns>A <see cref="MultiModalData"/> instance wrapping the <paramref name="item"/>.</returns>
/// <exception cref="ArgumentException">
/// Thrown if the <paramref name="item"/> is not a <see cref="TextContent"/> or <see cref="DataContent"/>.
/// </exception>
public static MultiModalData CheckTypeAndCreate(AIContent item)
{
if (item is TextContent text)
{
return new MultiModalData(text);
}
else if (item is DataContent image)
{
return new MultiModalData(image);
}
else
{
throw new ArgumentException("Only TextContent and ImageContent are allowed in MultiModalMessage");
}
}
/// <summary>
/// Initializes a new instance of the <see cref="MultiModalData"/> with a <see cref="string"/>.
/// </summary>
/// <param name="text">The text to wrap.</param>
public MultiModalData(string text)
{
ContentType = Type.String;
AIContent = new TextContent(text);
}
/// <summary>
/// Initializes a new instance of the <see cref="MultiModalData"/> with a <see cref="TextContent"/>.
/// </summary>
/// <param name="textContent">The <see cref="TextContent"/> to wrap.</param>
public MultiModalData(TextContent textContent)View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before
var items = new List<AIContent> { new TextContent("listen"), new AudioContent(bytes, "audio/wav") };
var msg = new MultiModalMessage(items);
// after
var items = new List<AIContent> { new TextContent("listen"), new DataContent(new Uri("data:audio/wav;base64,...")) };
// or keep only text and handle audio separately Defensive patterns
Strategy: type-guard
Validate before calling
var valid = items.All(i => i is TextContent or DataContent);
if (!valid) throw new ArgumentException("MultiModalMessage only accepts TextContent and DataContent items");
var msg = new MultiModalMessage(items); Type guard
static bool IsMultiModalSupported(AIContent content) => content is TextContent or DataContent;
Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("Only TextContent and ImageContent")) { // downgrade: convert item to TextContent or route it outside the multimodal message } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported content type {item.GetType()}
- Invalid aggregate message {reason}
- Invalid ChatResponseMessage
- The method or operation is not implemented.
- Unsupported content type
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/fb5baa359e7e5db6.
Report an issue: GitHub.