{"record":{"id":"b0a7611eb26762ad","repo":"microsoft/autogen","slug":"content-is-null","errorCode":null,"errorMessage":"Content is null","messagePattern":"Content is null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs","lineNumber":146,"sourceCode":"                else if (msg.FunctionName is null && msg.FunctionArguments is null)\n                {\n                    var userMessage = msg.ToChatRequestUserMessage();\n                    return [userMessage];\n                }\n                else if (msg.FunctionName is not null && msg.FunctionArguments is not null && msg.Content is not null)\n                {\n                    if (msg.Role == Role.Function)\n                    {\n                        return [new ChatRequestFunctionMessage(msg.FunctionName, msg.Content)];\n                    }\n                    else\n                    {\n                        return [new ChatRequestUserMessage(msg.Content)];\n                    }\n                }\n                else\n                {\n                    var userMessage = new ChatRequestUserMessage(msg.Content ?? throw new ArgumentException(\"Content is null\"));\n                    return [userMessage];\n                }\n            }\n            else\n            {\n                throw new ArgumentException($\"Unknown message type: {message.GetType()}\");\n            }\n        }\n        else\n        {\n            if (message is TextMessage textMessage)\n            {\n                if (textMessage.Role == Role.System)\n                {\n                    throw new ArgumentException(\"System message is not supported when message.From is the same with agent\");\n                }\n\n                return [new ChatRequestAssistantMessage(textMessage.Content)];","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"Empty assistant turns or placeholder messages accumulated in group-chat history; message objects created with default constructors; content dropped during serialization/deserialization of history.","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"],"exampleFix":"// before\nhistory.Add(new TextMessage(Role.User, null));\nawait agent.SendAsync(history);\n\n// after\nhistory = history.Where(m => !string.IsNullOrEmpty(m.GetContent())).ToList();\nawait agent.SendAsync(history);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(msg.GetContent()))\n    throw new ArgumentException($\"Message from {msg.From} has null content\");","typeGuard":null,"tryCatchPattern":"catch (ArgumentException ex) when (ex.Message == \"Content is null\")\n{\n    logger.LogWarning(\"Skipping message with null content from {From}\", msg.From);\n}","preventionTips":["Skip null-content messages when replaying history","Avoid default-constructed message objects","Assert content non-empty at message creation"],"tags":["openai","content-null","message-conversion","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}