{"record":{"id":"7e1f84ddd743f976","repo":"microsoft/autogen","slug":"unsupported-message-type-reply-gettype","errorCode":null,"errorMessage":"Unsupported message type: {reply.GetType()}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":69,"sourceCode":"            {\n                // if m.Content is empty and stop reason is Stop, ignore the message\n                if (m.Content.Candidates.Count == 1 && m.Content.Candidates[0].Content.Parts.Count == 1 && m.Content.Candidates[0].Content.Parts[0].DataCase == Part.DataOneofCase.Text)\n                {\n                    var text = m.Content.Candidates[0].Content.Parts[0].Text;\n                    var stopReason = m.Content.Candidates[0].FinishReason;\n                    if (string.IsNullOrEmpty(text) && stopReason == FinishReason.Stop)\n                    {\n                        continue;\n                    }\n                }\n\n                bucket.Add(m.Content);\n\n                yield return PostProcessStreamingMessage(m.Content, agent);\n            }\n            else if (strictMode)\n            {\n                throw new InvalidOperationException($\"Unsupported message type: {reply.GetType()}\");\n            }\n            else\n            {\n                yield return reply;\n            }\n\n            // aggregate the message updates from bucket into a single message\n            if (bucket is { Count: > 0 })\n            {\n                var isTextMessageUpdates = bucket.All(m => m.Candidates.Count == 1 && m.Candidates[0].Content.Parts.Count == 1 && m.Candidates[0].Content.Parts[0].DataCase == Part.DataOneofCase.Text);\n                var isFunctionCallUpdates = bucket.Any(m => m.Candidates.Count == 1 && m.Candidates[0].Content.Parts.Count == 1 && m.Candidates[0].Content.Parts[0].DataCase == Part.DataOneofCase.FunctionCall);\n                if (isTextMessageUpdates)\n                {\n                    var text = string.Join(string.Empty, bucket.Select(m => m.Candidates[0].Content.Parts[0].Text));\n                    var textMessage = new TextMessage(Role.Assistant, text, agent.Name);\n\n                    yield return textMessage;\n                }","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L51-L87","documentation":"Thrown by GeminiMessageConnector's STREAMING path when strictMode is enabled and the agent's streaming reply item is not IMessage<GenerateContentResponse>. In strict mode the connector refuses to pass through foreign message types; non-strict mode simply yields them unchanged.","triggerScenarios":"Constructing GeminiMessageConnector(strictMode: true) and having the wrapped streaming agent yield AutoGen Core message types (TextMessageUpdate, ToolCallMessageUpdate, MessageEnvelope of other payloads) instead of Gemini GenerateContentResponse envelopes.","commonSituations":"Composing middleware where another middleware already converted chunks to Core types before the connector sees them, or wrapping a non-Gemini streaming agent by mistake.","solutions":["Register GeminiMessageConnector directly against the GeminiChatAgent so it sees raw GenerateContentResponse streams (use the provided agent-registration helper for correct ordering)","Run the connector in non-strict mode (default) so foreign types pass through untouched","Remove any middleware between the Gemini agent and the connector that pre-converts messages"],"exampleFix":"// before:\nvar agent = new GeminiChatAgent(...).RegisterStreamingMiddleware(new GeminiMessageConnector(strictMode: true));\n// middleware ordering yields Core types into connector -> throw\n// after:\nvar agent = new GeminiChatAgent(...).RegisterMessageConnector(); // correct order, default non-strict","handlingStrategy":"fallback","validationCode":"null","typeGuard":"static bool IsGeminiStreamingReply(IMessage m) => m is IMessage<GenerateContentResponse>;","tryCatchPattern":"try { await foreach (var m in streamingGeminiAgent.GenerateStreamingReplyAsync(msgs, ct)) { } }\ncatch (InvalidOperationException e) when (e.Message.Contains(\"Unsupported message type\") && strictMode)\n{ /* rerun with non-strict connector: new GeminiMessageConnector() */ }","preventionTips":["Use the agent helper that registers the connector in the correct position","Default to non-strict mode unless you specifically need type enforcement"],"tags":["autogen","gemini","middleware","streaming"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}