microsoft/autogen · error · NotSupportedException
Message type {m.GetType()} is not supported.
Error message
Message type {m.GetType()} is not supported. What it means
Thrown by GeminiChatAgent.BuildChatRequest when a message in the conversation is not an IMessage<Content> (the Gemini-native content envelope). AutoGen's Gemini agent does not convert arbitrary message types, so any TextMessage/ToolCallMessage sent raw into GeminiChatAgent triggers NotSupportedException with the offending CLR type name.
Source
Thrown at dotnet/src/AutoGen.Gemini/GeminiChatAgent.cs:162
}
public async IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
var request = BuildChatRequest(messages, options);
var response = this.client.GenerateContentStreamAsync(request);
await foreach (var item in response.WithCancellation(cancellationToken).ConfigureAwait(false))
{
yield return MessageEnvelope.Create(item, this.Name);
}
}
private GenerateContentRequest BuildChatRequest(IEnumerable<IMessage> messages, GenerateReplyOptions? options)
{
var geminiMessages = messages.Select(m => m switch
{
IMessage<Content> contentMessage => contentMessage.Content,
_ => throw new NotSupportedException($"Message type {m.GetType()} is not supported.")
});
// there are several rules applies to the messages that can be sent to Gemini in a multi-turn chat
// - The first message must be from the user or function
// - The (user|model) roles must alternate e.g. (user, model, user, model, ...)
// - The last message must be from the user or function
// check if the first message is from the user
if (geminiMessages.FirstOrDefault()?.Role != "user" && geminiMessages.FirstOrDefault()?.Role != "function")
{
throw new ArgumentException("The first message must be from the user or function", nameof(messages));
}
// check if the last message is from the user
if (geminiMessages.LastOrDefault()?.Role != "user" && geminiMessages.LastOrDefault()?.Role != "function")
{
throw new ArgumentException("The last message must be from the user or function", nameof(messages));
}View on GitHub (pinned to 027ecf0a37)
Solutions
- Register GeminiMessageConnector middleware on the Gemini agent so messages are converted to IMessage<Content> before the request is built (use the Gemini agent creation helper which does this for you)
- If you build GeminiChatAgent manually, wrap payloads yourself in MessageEnvelope.Create(Content, from)
- In multi-provider chats, insert the appropriate provider connector middleware on each agent
Example fix
// before:
var agent = new GeminiChatAgent(...);
await agent.GenerateReplyAsync(new[] { new TextMessage(Role.User, "hi") }); // throws
// after:
var agent = new GeminiChatAgent(...)
.RegisterMessageConnector(); // GeminiMessageConnector converts TextMessage -> Content Defensive patterns
Strategy: type-guard
Validate before calling
// Verify every outgoing message is Gemini-native before calling the raw agent
if (messages.Any(m => m is not IMessage<Content>))
messages = ConvertViaConnector(messages); // or ensure connector middleware is registered Type guard
static bool AllGeminiNative(IEnumerable<IMessage> msgs) =>
msgs.All(m => m is IMessage<Content>); Try / catch
try { return await geminiAgent.GenerateReplyAsync(messages, options, ct); }
catch (NotSupportedException e) when (e.Message.Contains("not supported"))
{ /* register GeminiMessageConnector on the agent and retry */ } Prevention
- Always create Gemini agents via the library helper that registers the message connector
- Never forward other providers' messages verbatim to GeminiChatAgent
When it happens
Trigger: Sending messages (TextMessage, ToolCallMessage, ImageMessage, or custom IMessage) directly to GeminiChatAgent.GenerateReplyAsync without the GeminiMessageConnector middleware in the pipeline.
Common situations: Using the low-level GeminiChatAgent instead of the factory helper that registers GeminiMessageConnector; mixing agents from different providers in one chat and forwarding their replies verbatim to Gemini; upgrades where connector registration moved from implicit to explicit.
Related errors
- Unsupported message type: {reply.GetType()}
- No user message found.
- No user message found.
- The first message is ToolCallMessage, but the update message
- FunctionMap is not available
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/e37eaeaa82a21432.
Report an issue: GitHub.