{"record":{"id":"77c1579ae4dc4d3e","repo":"microsoft/autogen","slug":"unsupported-message-type-m-gettype-77c157","errorCode":null,"errorMessage":"Unsupported message type {m.GetType()}","messagePattern":"Unsupported message type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs","lineNumber":126,"sourceCode":"            doneMessage.Choices = [doneChoice];\n\n            yield return doneMessage;\n        }\n        else\n        {\n            yield return await this.GetChatCompletionAsync(request);\n        }\n    }\n\n    private IEnumerable<IMessage> ProcessMessages(IEnumerable<OpenAIMessage> messages)\n    {\n        return messages.Select<OpenAIMessage, IMessage>(m => m switch\n        {\n            OpenAISystemMessage systemMessage when systemMessage.Content is string content => new TextMessage(Role.System, content, this.agent.Name),\n            OpenAIUserMessage userMessage when userMessage.Content is string content => new TextMessage(Role.User, content, this.agent.Name),\n            OpenAIAssistantMessage assistantMessage when assistantMessage.Content is string content => new TextMessage(Role.Assistant, content, this.agent.Name),\n            OpenAIUserMultiModalMessage userMultiModalMessage when userMultiModalMessage.Content is { Length: > 0 } => this.CreateMultiModaMessageFromOpenAIUserMultiModalMessage(userMultiModalMessage),\n            _ => 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));","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs#L108-L144","documentation":"OpenAIChatCompletionService.ProcessMessages translates each incoming OpenAIMessage into a TextMessage/MultiModalMessage, but each case arm has a 'when' guard requiring non-null string content (or non-empty content array). Any message whose content is null, an unexpected type, or any unknown OpenAIMessage subclass falls through to ArgumentException 'Unsupported message type {type}'.","triggerScenarios":"POSTing a user/assistant/system message with content:null, a tool message (no case exists for OpenAIToolMessage in this method), or a user message whose content array is empty.","commonSituations":"Clients replaying tool-calling transcripts (tool role has no mapping here), assistant pre-fill messages with null content, or empty content arrays from edge-case UIs.","solutions":["Send only system/user/assistant messages with non-null string content, plus user multimodal messages with a non-empty content array","Strip tool messages and null-content turns from the history before calling the endpoint","For assistant pre-fill, send content:\"\" instead of null","Catch ArgumentException in the controller and return 400 with the rejected message type name"],"exampleFix":"// before\n{\"role\":\"assistant\",\"content\":null}\n\n// after\n{\"role\":\"assistant\",\"content\":\"\"}","handlingStrategy":"validation","validationCode":"var rejected = request.Messages.Where(m =>\n    !(m.Content is string)\n    && !(m is OpenAIUserMultiModalMessage mm && mm.Content is { Length: > 0 })).ToList();\nif (rejected.Count > 0)\n    return BadRequest($\"Messages with null/unsupported content: {string.Join(\",\", rejected.Select(m => m.GetType().Name))}\");","typeGuard":"static bool IsAcceptableOpenAIMessage(OpenAIMessage m) => m switch\n{\n    OpenAISystemMessage { Content: string } => true,\n    OpenAIUserMessage { Content: string } => true,\n    OpenAIAssistantMessage { Content: string } => true,\n    OpenAIUserMultiModalMessage { Content: { Length: > 0 } } => true,\n    _ => false\n};","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.Contains(\"Unsupported message type\"))\n{\n    return BadRequest(new { error = \"unsupported_message\", detail = ex.Message });\n}","preventionTips":["Never send null content; use an empty string for assistant pre-fill","Drop tool messages before calling this endpoint","Validate the messages array client-side with IsAcceptableOpenAIMessage-style checks"],"tags":["csharp","webapi","openai-compatible","message-type","argument"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}