microsoft/autogen · error · InvalidOperationException

Unsupported message type: {item.GetType().Name}

Error message

Unsupported message type: {item.GetType().Name}

What it means

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.

Source

Thrown at dotnet/src/AutoGen.SemanticKernel/Middleware/SemanticKernelChatMessageContentConnector.cs:220

        throw new System.InvalidOperationException("MultiModalMessage is not supported in the semantic kernel if it's from self.");
    }

    private IEnumerable<ChatMessageContent> ProcessMessageForOthers(MultiModalMessage message)
    {
        var collections = new ChatMessageContentItemCollection();
        foreach (var item in message.Content)
        {
            if (item is TextMessage textContent)
            {
                collections.Add(new TextContent(textContent.Content));
            }
            else if (item is ImageMessage imageContent)
            {
                collections.Add(new ImageContent(new Uri(imageContent.Url ?? imageContent.BuildDataUri())));
            }
            else
            {
                throw new InvalidOperationException($"Unsupported message type: {item.GetType().Name}");
            }
        }
        return [new ChatMessageContent(AuthorRole.User, collections)];
    }

    [Obsolete("This method is deprecated, please use the specific method instead.")]
    private IEnumerable<ChatMessageContent> ProcessMessageForSelf(Message message)
    {
        if (message.Role == Role.System)
        {
            return [new ChatMessageContent(AuthorRole.System, message.Content)];
        }
        else if (message.Content is string && message.FunctionName is null && message.FunctionArguments is null)
        {
            return [new ChatMessageContent(AuthorRole.Assistant, message.Content)];
        }
        else if (message.Content is null && message.FunctionName is not null && message.FunctionArguments is not null)
        {

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Construct MultiModalMessage with only TextMessage and ImageMessage items.
  2. Project/flatten other message types into text (stringify JSON) before adding them to the collection.
  3. Add a validation pass over multimodal content at build time (see defense section) to fail early with context.

Example fix

// before
var content = new IMessage[] { new TextMessage(Role.User, "hi"), toolCallResult };
var mm = new MultiModalMessage(Role.User, content);

// after
var content = new IMessage[] { new TextMessage(Role.User, "hi"), new TextMessage(Role.User, toolCallResult.ToString()) };
var mm = new MultiModalMessage(Role.User, content);
Defensive patterns

Strategy: type-guard

Validate before calling

if (multiModal.Content.Any(i => i is not (TextMessage or ImageMessage)))
    throw new ArgumentException("MultiModalMessage items for SK must be TextMessage or ImageMessage.");

Type guard

static bool IsValidSkMultimodalContent(IEnumerable<IMessage> items) =>
    items.All(i => i is TextMessage or ImageMessage);

Try / catch

catch (InvalidOperationException ex) when (ex.Message.StartsWith("Unsupported message type:"))
{
    logger.LogError("Bad multimodal item: {Message}", ex.Message);
    throw;
}

Prevention

When it happens

Trigger: Building MultiModalMessage.Content with items other than TextMessage/ImageMessage (e.g. ToolCallMessage or a custom message) and sending it to an SK agent.

Common situations: Generically mapping a mixed message list into multimodal content; adding new message kinds to an existing multimodal builder without updating consumers.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/1230ff70a26806c9. Report an issue: GitHub.