{"record":{"id":"5c2c02a9c8f7fc07","repo":"microsoft/autogen","slug":"invalid-message-type-m-gettype-name-5c2c02","errorCode":null,"errorMessage":"Invalid message type: {m.GetType().Name}","messagePattern":"Invalid message type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":192,"sourceCode":"            if (m is IMessage<ChatRequestMessage> crm)\n            {\n                return [crm];\n            }\n            else\n            {\n                var chatRequestMessages = m switch\n                {\n                    TextMessage textMessage => ProcessTextMessage(agent, textMessage),\n                    ImageMessage imageMessage when (imageMessage.From is null || imageMessage.From != agent.Name) => ProcessImageMessage(agent, imageMessage),\n                    MultiModalMessage multiModalMessage when (multiModalMessage.From is null || multiModalMessage.From != agent.Name) => ProcessMultiModalMessage(agent, multiModalMessage),\n                    ToolCallMessage toolCallMessage when (toolCallMessage.From is null || toolCallMessage.From == agent.Name) => ProcessToolCallMessage(agent, toolCallMessage),\n                    ToolCallResultMessage toolCallResultMessage => ProcessToolCallResultMessage(toolCallResultMessage),\n                    AggregateMessage<ToolCallMessage, ToolCallResultMessage> aggregateMessage => ProcessFunctionCallMiddlewareMessage(agent, aggregateMessage),\n#pragma warning disable CS0618 // deprecated\n                    Message msg => ProcessMessage(agent, msg),\n#pragma warning restore CS0618 // deprecated\n                    _ when strictMode is false => [],\n                    _ => throw new InvalidOperationException($\"Invalid message type: {m.GetType().Name}\"),\n                };\n\n                if (chatRequestMessages.Any())\n                {\n                    return chatRequestMessages.Select(cm => MessageEnvelope.Create(cm, m.From));\n                }\n                else\n                {\n                    return [m];\n                }\n            }\n        });\n    }\n\n    [Obsolete(\"This method is deprecated, please use ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages) instead.\")]\n    private IEnumerable<ChatRequestMessage> ProcessIncomingMessagesForSelf(Message message)\n    {\n        if (message.Role == Role.System)","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L174-L210","documentation":"Thrown by ProcessIncomingMessages when strictMode is true and an incoming IMessage is not one of the supported types (TextMessage, ImageMessage, MultiModalMessage, ToolCallMessage, ToolCallResultMessage, AggregateMessage<ToolCallMessage,ToolCallResultMessage>, legacy Message, or ChatRequestMessage envelopes). In strict mode the connector must translate every message into Azure OpenAI ChatRequestMessage form; anything unrecognized aborts the batch.","triggerScenarios":"Sending a message type like MessageEnvelope<someCustomPayload>, Microsoft.AutoGen messages, or another provider's message class into an agent pipeline containing this connector built with strictMode: true.","commonSituations":"Heterogeneous group chats where agents from different AutoGen packages share one conversation; custom user-defined IMessage implementations; strict-mode enabled to catch message-flow bugs but foreign messages legitimately flow through.","solutions":["Construct the connector with strictMode: false so unsupported messages are forwarded unchanged","Convert foreign messages to TextMessage/MessageEnvelope<ChatRequestMessage> before they reach this agent","If the message is from another agent, ensure it is an aggregate or tool-call/result type the connector understands","Log m.GetType().Name at the call site to identify the offending producer"],"exampleFix":"// before\nvar connector = new OpenAIChatRequestMessageConnector(strictMode: true);\nawait agent.SendAsync(new MessageEnvelope<MyPayload>(new MyPayload())); // throws\n\n// after\nvar connector = new OpenAIChatRequestMessageConnector(); // lenient passthrough\n// or wrap the payload: new TextMessage(Role.User, Serialize(myPayload))","handlingStrategy":"type-guard","validationCode":"var supported = msg is TextMessage or ImageMessage or MultiModalMessage or ToolCallMessage or ToolCallResultMessage or AggregateMessage<ToolCallMessage, ToolCallResultMessage> or IMessage<ChatRequestMessage>;\nif (!supported && strictMode) { /* convert to TextMessage first */ }","typeGuard":"static bool IsSupportedByV1Connector(IMessage m) => m is TextMessage or ImageMessage or MultiModalMessage or ToolCallMessage or ToolCallResultMessage or AggregateMessage<ToolCallMessage, ToolCallResultMessage> or IMessage<ChatRequestMessage>;","tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Invalid message type\")) { /* convert or drop the offending message */ }","preventionTips":["Standardize on AutoGen core message types across agents","Keep strictMode off for heterogeneous group chats","Unit-test message routing with every message type your app produces"],"tags":["autogen","dotnet","azure-openai","middleware","strict-mode","message-connector"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}