microsoft/autogen · error · InvalidOperationException
Unsupported message type: {m.GetType()}
Error message
Unsupported message type: {m.GetType()} What it means
Thrown by GeminiMessageConnector.ProcessMessage when strictMode is enabled (GeminiMessageConnector strictMode: true) and an incoming IMessage does not match any of the supported message types (TextMessage, ImageMessage, MultiModalMessage, ToolCallMessage, ToolCallResultMessage, ToolCallAggregateMessage, or an IMessage<Content> envelope). Strict mode exists to surface mapping gaps instead of silently passing untranslatable messages to Gemini.
Source
Thrown at dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs:220
private IEnumerable<IMessage> ProcessMessage(IEnumerable<IMessage> messages, IAgent agent)
{
return messages.SelectMany(m =>
{
if (m is Core.IMessage<Content> messageEnvelope)
{
return [m];
}
else
{
return m switch
{
TextMessage textMessage => ProcessTextMessage(textMessage, agent),
ImageMessage imageMessage => ProcessImageMessage(imageMessage, agent),
MultiModalMessage multiModalMessage => ProcessMultiModalMessage(multiModalMessage, agent),
ToolCallMessage toolCallMessage => ProcessToolCallMessage(toolCallMessage, agent),
ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage, agent),
ToolCallAggregateMessage toolCallAggregateMessage => ProcessToolCallAggregateMessage(toolCallAggregateMessage, agent),
_ when strictMode => throw new InvalidOperationException($"Unsupported message type: {m.GetType()}"),
_ => [m],
};
}
});
}
private IEnumerable<IMessage> ProcessToolCallAggregateMessage(ToolCallAggregateMessage toolCallAggregateMessage, IAgent agent)
{
var parseAsUser = ShouldParseAsUser(toolCallAggregateMessage, agent);
if (parseAsUser)
{
var content = toolCallAggregateMessage.GetContent();
if (content is string str)
{
var textMessage = new TextMessage(Role.User, str, toolCallAggregateMessage.From);
return ProcessTextMessage(textMessage, agent);View on GitHub (pinned to 027ecf0a37)
Solutions
- Convert foreign/custom messages to TextMessage (or MultiModalMessage) before they reach the Gemini agent.
- Use the non-strict constructor (strictMode defaults to false) if passing unknown messages through is acceptable.
- Wrap the payload as MessageEnvelope.Create(content) with Gemini Content if you already have Gemini-shaped data.
- Log m.GetType() from the exception to find which producer emitted the unsupported type.
Example fix
// before
var connector = new GeminiMessageConnector(strictMode: true);
await geminiAgent.InitiateChatAsync(otherAgent, nil, new MyCustomMessage("hi"));
// after
var text = new TextMessage(Role.User, "hi", from: otherAgent.Name);
await geminiAgent.SendAsync(text); Defensive patterns
Strategy: type-guard
Type guard
static bool IsGeminiSupportedMessage(IMessage m) => m is TextMessage or ImageMessage or MultiModalMessage or ToolCallMessage or ToolCallResultMessage or ToolCallAggregateMessage or Core.IMessage<Content>;
Prevention
- Normalize all messages to TextMessage at group-chat boundaries
- Only enable strictMode when you control every producer in the graph
- Log message runtime types in tests
When it happens
Trigger: Constructing GeminiMessageConnector with strictMode:true and sending a message whose runtime type is outside the switch — e.g. a custom IMessage subclass, MessageEnvelope wrapping an unexpected payload, or another vendor's message type from a multi-agent pipeline.
Common situations: Heterogeneous agent graphs (Gemini agent talking to an LLM/OpenAI agent whose message type leaks through); custom middleware injecting proprietary message classes; strictMode turned on to harden a pipeline that previously relied on the lenient pass-through.
Related errors
- Unsupported message type: {message.GetType()}
- The response should contain exactly one candidate.
- ToolCallMessage is not supported as user role in Gemini.
- Image message is not supported as model role in Gemini.
- System role is not supported in Gemini.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/247aad4e85e791c2.
Report an issue: GitHub.