{"record":{"id":"6f51517e94cb8929","repo":"microsoft/autogen","slug":"value-cannot-be-null-parameter-content","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'Content')","messagePattern":"Value cannot be null\\. \\(Parameter 'Content'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"warning","filePath":"dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs","lineNumber":144,"sourceCode":"            _ => throw new ArgumentException($\"Unsupported message type {m.GetType()}\")\n        });\n    }\n\n    private GenerateReplyOptions ProcessReplyOptions(OpenAIChatCompletionOption request)\n    {\n        return new GenerateReplyOptions()\n        {\n            Temperature = request.Temperature,\n            MaxToken = request.MaxTokens,\n            StopSequence = request.Stop,\n        };\n    }\n\n    private MultiModalMessage CreateMultiModaMessageFromOpenAIUserMultiModalMessage(OpenAIUserMultiModalMessage message)\n    {\n        if (message.Content is null)\n        {\n            throw new ArgumentNullException(nameof(message.Content));\n        }\n\n        IEnumerable<IMessage> items = message.Content.Select<OpenAIUserMessageItem, IMessage>(item => item switch\n        {\n            OpenAIUserImageContent imageContent when imageContent.Url is string url => new ImageMessage(Role.User, url, this.agent.Name),\n            OpenAIUserTextContent textContent when textContent.Content is string content => new TextMessage(Role.User, content, this.agent.Name),\n            _ => throw new ArgumentException($\"Unsupported content type {item.GetType()}\")\n        });\n\n        return new MultiModalMessage(Role.User, items, this.agent.Name);\n    }\n}\n","sourceCodeStart":126,"sourceCodeEnd":157,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs#L126-L157","documentation":"CreateMultiModaMessageFromOpenAIUserMultiModalMessage guards against a null Content array with ArgumentNullException('Content'). In the normal ProcessMessages flow this is unreachable (the caller already required Length > 0), but any future caller that skips that guard, or a refactor of the 'when' clause, will hit it — it exists to fail fast rather than NRE inside LINQ Select.","triggerScenarios":"Invoking multimodal conversion with an OpenAIUserMultiModalMessage whose Content array is null — only possible if the ProcessMessages guard is removed or the method is called from new code paths.","commonSituations":"Refactoring ProcessMessages' pattern guards, adding a new message-mapping path that forgets the empty check, or deserialization changes that make Content default to null.","solutions":["Keep the 'when userMultiModalMessage.Content is { Length: > 0 }' guard intact in ProcessMessages","Treat null-content multimodal messages as empty input: skip them or reject with 400 before conversion","Add a unit test covering null and empty Content arrays for this method"],"exampleFix":"// before\nvar mm = new OpenAIUserMultiModalMessage { Content = null };\nCreateMultiModaMessageFromOpenAIUserMultiModalMessage(mm); // throws ArgumentNullException\n\n// after\nvar mm = new OpenAIUserMultiModalMessage { Content = Array.Empty<OpenAIUserMessageItem>() };\nif (mm.Content is { Length: > 0 }) CreateMultiModaMessageFromOpenAIUserMultiModalMessage(mm);","handlingStrategy":"validation","validationCode":"if (message.Content is null || message.Content.Length == 0)\n    return BadRequest(\"Multimodal content array must contain at least one item.\");\nvar mm = CreateMultiModaMessageFromOpenAIUserMultiModalMessage(message);","typeGuard":"static bool HasNonEmptyMultimodalContent(OpenAIUserMultiModalMessage m) => m.Content is { Length: > 0 };","tryCatchPattern":"catch (ArgumentNullException ex) when (ex.ParamName == \"Content\")\n{\n    return BadRequest(\"Multimodal message Content must not be null.\");\n}","preventionTips":["Keep the Length > 0 guard when refactoring ProcessMessages","Reject empty multimodal arrays at the controller boundary with 400","Unit-test null and empty content arrays against the conversion path"],"tags":["csharp","webapi","multimodal","null-argument","defensive-code"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}