microsoft/autogen · error · ArgumentException
Content is null and metadata is null
Error message
Content is null and metadata is null
What it means
MessageExtension's user-message conversion throws ArgumentException when a message has neither usable content nor recognized metadata. It first tries to build multi-modal items from metadata (e.g. image URLs under the image content-type key); if no items were produced and the Content is null/empty, nothing can be sent to the API.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:44
foreach (var item in message.Metadata)
{
if (item.Key == TEXT_CONTENT_TYPE && item.Value is string txt)
{
itemList.Add(new ChatMessageTextContentItem(txt));
}
else if (item.Key == IMAGE_CONTENT_TYPE && item.Value is string url)
{
itemList.Add(new ChatMessageImageContentItem(new Uri(url)));
}
}
if (itemList.Count > 0)
{
return new ChatRequestUserMessage(itemList);
}
else
{
throw new ArgumentException("Content is null and metadata is null");
}
}
else if (!string.IsNullOrEmpty(message?.Content))
{
return new ChatRequestUserMessage(message!.Content);
}
throw new ArgumentException("Content is null and metadata is null");
}
[Obsolete("This method is deprecated")]
public static IEnumerable<ChatRequestMessage> ToOpenAIChatRequestMessage(this IAgent agent, IMessage message)
{
if (message is IMessage<ChatRequestMessage> oaiMessage)
{
// short-circuit
return [oaiMessage.Content];
}View on GitHub (pinned to 027ecf0a37)
Solutions
- Ensure the message has non-empty Content before sending
- For image-only messages, set Metadata[IMAGE_CONTENT_TYPE] = imageUrl (string) so the multi-modal branch produces a content item
- Filter out empty messages from conversation history before conversion
Example fix
// before
var msg = new TextMessage(Role.User, content: null);
await agent.SendAsync(msg);
// after
var msg = new TextMessage(Role.User, "Describe this image")
{
Metadata = new Dictionary<string, object> { [IMAGE_CONTENT_TYPE] = imageUrl }
};
await agent.SendAsync(msg); Defensive patterns
Strategy: validation
Validate before calling
bool IsSendable(IMessage m) =>
!string.IsNullOrEmpty(m.GetContent()) ||
m.Metadata?.Any(kv => kv.Key == IMAGE_CONTENT_TYPE && kv.Value is string) == true; Try / catch
catch (ArgumentException ex) when (ex.Message == "Content is null and metadata is null")
{
logger.LogWarning("Dropped empty message");
} Prevention
- Never construct messages without content or image metadata
- Check message content before adding to history
- Use IMAGE_CONTENT_TYPE constant, not a hand-typed key
When it happens
Trigger: Calling the conversion with a TextMessage whose Content is null/empty and whose Metadata lacks IMAGE_CONTENT_TYPE entries, or an IMessage with null Content and null/empty Metadata.
Common situations: Passing placeholder or uninitialized messages into the connector; streaming partial updates where content hasn't arrived yet; metadata keys set with non-string values so the image branch is skipped.
Related errors
- Content is null
- Unknown message type: {m.GetType()}
- Unknown message type: {message.GetType()}
- Failed to fetch galleries
- Failed to fetch gallery
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/11d1d5aae12d916f.
Report an issue: GitHub.