{"record":{"id":"11d1d5aae12d916f","repo":"microsoft/autogen","slug":"content-is-null-and-metadata-is-null","errorCode":null,"errorMessage":"Content is null and metadata is null","messagePattern":"Content is null and metadata is null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs","lineNumber":44,"sourceCode":"            foreach (var item in message.Metadata)\n            {\n                if (item.Key == TEXT_CONTENT_TYPE && item.Value is string txt)\n                {\n                    itemList.Add(new ChatMessageTextContentItem(txt));\n                }\n                else if (item.Key == IMAGE_CONTENT_TYPE && item.Value is string url)\n                {\n                    itemList.Add(new ChatMessageImageContentItem(new Uri(url)));\n                }\n            }\n\n            if (itemList.Count > 0)\n            {\n                return new ChatRequestUserMessage(itemList);\n            }\n            else\n            {\n                throw new ArgumentException(\"Content is null and metadata is null\");\n            }\n        }\n        else if (!string.IsNullOrEmpty(message?.Content))\n        {\n            return new ChatRequestUserMessage(message!.Content);\n        }\n\n        throw new ArgumentException(\"Content is null and metadata is null\");\n    }\n\n    [Obsolete(\"This method is deprecated\")]\n    public static IEnumerable<ChatRequestMessage> ToOpenAIChatRequestMessage(this IAgent agent, IMessage message)\n    {\n        if (message is IMessage<ChatRequestMessage> oaiMessage)\n        {\n            // short-circuit\n            return [oaiMessage.Content];\n        }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar msg = new TextMessage(Role.User, content: null);\nawait agent.SendAsync(msg);\n\n// after\nvar msg = new TextMessage(Role.User, \"Describe this image\")\n{\n    Metadata = new Dictionary<string, object> { [IMAGE_CONTENT_TYPE] = imageUrl }\n};\nawait agent.SendAsync(msg);","handlingStrategy":"validation","validationCode":"bool IsSendable(IMessage m) =>\n    !string.IsNullOrEmpty(m.GetContent()) ||\n    m.Metadata?.Any(kv => kv.Key == IMAGE_CONTENT_TYPE && kv.Value is string) == true;","typeGuard":null,"tryCatchPattern":"catch (ArgumentException ex) when (ex.Message == \"Content is null and metadata is null\")\n{\n    logger.LogWarning(\"Dropped empty message\");\n}","preventionTips":["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"],"tags":["openai","message-conversion","content-null","multi-modal"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}