microsoft/autogen · error · ArgumentException
Content is null
Error message
Content is null
What it means
Thrown when converting a foreign (different-sender) message whose conversion path reaches new ChatRequestUserMessage(msg.Content) but Content is null. The code defends with Content ?? throw ArgumentException because ChatRequestUserMessage requires non-null user text.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:146
else if (msg.FunctionName is null && msg.FunctionArguments is null)
{
var userMessage = msg.ToChatRequestUserMessage();
return [userMessage];
}
else if (msg.FunctionName is not null && msg.FunctionArguments is not null && msg.Content is not null)
{
if (msg.Role == Role.Function)
{
return [new ChatRequestFunctionMessage(msg.FunctionName, msg.Content)];
}
else
{
return [new ChatRequestUserMessage(msg.Content)];
}
}
else
{
var userMessage = new ChatRequestUserMessage(msg.Content ?? throw new ArgumentException("Content is null"));
return [userMessage];
}
}
else
{
throw new ArgumentException($"Unknown message type: {message.GetType()}");
}
}
else
{
if (message is TextMessage textMessage)
{
if (textMessage.Role == Role.System)
{
throw new ArgumentException("System message is not supported when message.From is the same with agent");
}
return [new ChatRequestAssistantMessage(textMessage.Content)];View on GitHub (pinned to 027ecf0a37)
Solutions
- Guarantee Content is non-empty before adding the message to any conversation sent to OpenAI agents
- Prune null-content messages when loading persisted history
- Initialize message content to string.Empty and skip empty strings before sending
Example fix
// before history.Add(new TextMessage(Role.User, null)); await agent.SendAsync(history); // after history = history.Where(m => !string.IsNullOrEmpty(m.GetContent())).ToList(); await agent.SendAsync(history);
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(msg.GetContent()))
throw new ArgumentException($"Message from {msg.From} has null content"); Try / catch
catch (ArgumentException ex) when (ex.Message == "Content is null")
{
logger.LogWarning("Skipping message with null content from {From}", msg.From);
} Prevention
- Skip null-content messages when replaying history
- Avoid default-constructed message objects
- Assert content non-empty at message creation
When it happens
Trigger: A message from another agent with null Content (e.g. an empty TextMessage or partially-built message) hits the generic user-message branch of the foreign-sender path.
Common situations: Empty assistant turns or placeholder messages accumulated in group-chat history; message objects created with default constructors; content dropped during serialization/deserialization of history.
Related errors
- Content is null and metadata is null
- Unsupported config type {config.GetType()}
- Messages should not be provided in options
- Parameter name cannot be null
- Unknown message type: {m.GetType()}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/b0a7611eb26762ad.
Report an issue: GitHub.