microsoft/autogen · error · ArgumentException
Unsupported message type {m.GetType()}
Error message
Unsupported message type {m.GetType()} What it means
OpenAIChatCompletionService.ProcessMessages translates each incoming OpenAIMessage into a TextMessage/MultiModalMessage, but each case arm has a 'when' guard requiring non-null string content (or non-empty content array). Any message whose content is null, an unexpected type, or any unknown OpenAIMessage subclass falls through to ArgumentException 'Unsupported message type {type}'.
Source
Thrown at dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs:126
doneMessage.Choices = [doneChoice];
yield return doneMessage;
}
else
{
yield return await this.GetChatCompletionAsync(request);
}
}
private IEnumerable<IMessage> ProcessMessages(IEnumerable<OpenAIMessage> messages)
{
return messages.Select<OpenAIMessage, IMessage>(m => m switch
{
OpenAISystemMessage systemMessage when systemMessage.Content is string content => new TextMessage(Role.System, content, this.agent.Name),
OpenAIUserMessage userMessage when userMessage.Content is string content => new TextMessage(Role.User, content, this.agent.Name),
OpenAIAssistantMessage assistantMessage when assistantMessage.Content is string content => new TextMessage(Role.Assistant, content, this.agent.Name),
OpenAIUserMultiModalMessage userMultiModalMessage when userMultiModalMessage.Content is { Length: > 0 } => this.CreateMultiModaMessageFromOpenAIUserMultiModalMessage(userMultiModalMessage),
_ => throw new ArgumentException($"Unsupported message type {m.GetType()}")
});
}
private GenerateReplyOptions ProcessReplyOptions(OpenAIChatCompletionOption request)
{
return new GenerateReplyOptions()
{
Temperature = request.Temperature,
MaxToken = request.MaxTokens,
StopSequence = request.Stop,
};
}
private MultiModalMessage CreateMultiModaMessageFromOpenAIUserMultiModalMessage(OpenAIUserMultiModalMessage message)
{
if (message.Content is null)
{
throw new ArgumentNullException(nameof(message.Content));View on GitHub (pinned to 027ecf0a37)
Solutions
- Send only system/user/assistant messages with non-null string content, plus user multimodal messages with a non-empty content array
- Strip tool messages and null-content turns from the history before calling the endpoint
- For assistant pre-fill, send content:"" instead of null
- Catch ArgumentException in the controller and return 400 with the rejected message type name
Example fix
// before
{"role":"assistant","content":null}
// after
{"role":"assistant","content":""} Defensive patterns
Strategy: validation
Validate before calling
var rejected = request.Messages.Where(m =>
!(m.Content is string)
&& !(m is OpenAIUserMultiModalMessage mm && mm.Content is { Length: > 0 })).ToList();
if (rejected.Count > 0)
return BadRequest($"Messages with null/unsupported content: {string.Join(",", rejected.Select(m => m.GetType().Name))}"); Type guard
static bool IsAcceptableOpenAIMessage(OpenAIMessage m) => m switch
{
OpenAISystemMessage { Content: string } => true,
OpenAIUserMessage { Content: string } => true,
OpenAIAssistantMessage { Content: string } => true,
OpenAIUserMultiModalMessage { Content: { Length: > 0 } } => true,
_ => false
}; Try / catch
catch (ArgumentException ex) when (ex.Message.Contains("Unsupported message type"))
{
return BadRequest(new { error = "unsupported_message", detail = ex.Message });
} Prevention
- Never send null content; use an empty string for assistant pre-fill
- Drop tool messages before calling this endpoint
- Validate the messages array client-side with IsAcceptableOpenAIMessage-style checks
When it happens
Trigger: POSTing a user/assistant/system message with content:null, a tool message (no case exists for OpenAIToolMessage in this method), or a user message whose content array is empty.
Common situations: Clients replaying tool-calling transcripts (tool role has no mapping here), assistant pre-fill messages with null content, or empty content arrays from edge-case UIs.
Related errors
- Invalid message type
- Invalid message type
- Exception of type 'System.Text.Json.JsonException' was throw
- Unsupported reply content type
- Value cannot be null. (Parameter 'Content')
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/77c1579ae4dc4d3e.
Report an issue: GitHub.