{"record":{"id":"06ee0263af6bf985","repo":"microsoft/semantic-kernel","slug":"unsupported-content-type-item-gettype-name-is","errorCode":null,"errorMessage":"Unsupported content type. {item.GetType().Name} is not supported by Gemini.","messagePattern":"Unsupported content type\\. (.+?) is not supported by Gemini\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs","lineNumber":283,"sourceCode":"                // Apply signature to last text part\n                var lastTextPart = parts.LastOrDefault(p => p.Text is not null);\n                if (lastTextPart is not null)\n                {\n                    lastTextPart.ThoughtSignature = signature;\n                }\n            }\n        }\n\n        return parts;\n    }\n\n    private static GeminiPart GetGeminiPartFromKernelContent(KernelContent item) => item switch\n    {\n        TextContent textContent => new GeminiPart { Text = textContent.Text },\n        ImageContent imageContent => CreateGeminiPartFromImage(imageContent),\n        AudioContent audioContent => CreateGeminiPartFromAudio(audioContent),\n        BinaryContent binaryContent => CreateGeminiPartFromBinary(binaryContent),\n        _ => throw new NotSupportedException($\"Unsupported content type. {item.GetType().Name} is not supported by Gemini.\")\n    };\n\n    private static GeminiPart CreateGeminiPartFromImage(ImageContent imageContent)\n    {\n        // Binary data takes precedence over URI as per the ImageContent.ToString() implementation.\n        if (imageContent.Data is { IsEmpty: false })\n        {\n            return new GeminiPart\n            {\n                InlineData = new GeminiPart.InlineDataPart\n                {\n                    MimeType = GetMimeTypeFromImageContent(imageContent),\n                    InlineData = Convert.ToBase64String(imageContent.Data.Value.ToArray())\n                }\n            };\n        }\n\n        if (imageContent.Uri is not null)","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs#L265-L301","documentation":"Thrown by GeminiRequest.GetGeminiPartFromKernelContent when a KernelContent item in the collection is not one of the four recognized types: TextContent, ImageContent, AudioContent, or BinaryContent. The switch expression exhausts these four cases and falls to the default throw for any other KernelContent subclass.","triggerScenarios":"Passing a chat history or content collection containing a custom KernelContent subclass, or a built-in type not yet mapped (e.g. FunctionCallContent, FunctionResultContent, or a future SK content type). The conversion happens when SK builds the Gemini request from the kernel content.","commonSituations":"Adding a custom KernelContent subclass for application-specific metadata. Using FunctionCallContent or FunctionResultContent directly in chat history (these are typically handled through tool-call paths, not content conversion). Newer SK versions introduce content types the connector does not yet support.","solutions":["Filter chat history to only include TextContent, ImageContent, AudioContent, or BinaryContent before passing to the Gemini connector.","Convert custom content types to TextContent or another supported type before the call.","Upgrade the Connectors.Google package if a newer version supports the content type you need.","If using function calling, ensure FunctionCallContent/FunctionResultContent are handled through the tool-call pipeline, not manually added to history."],"exampleFix":"// before — custom content type in history\nhistory.Items.Add(new MyCustomContent());\nawait client.GetChatMessageContentsAsync(history);\n\n// after — filter to supported types\nvar supported = history.Where(m => m.Items.All(i =>\n    i is TextContent or ImageContent or AudioContent or BinaryContent)).ToList();\nawait client.GetChatMessageContentsAsync(supported);","handlingStrategy":"type-guard","validationCode":"var supportedTypes = new HashSet<Type>\n{\n    typeof(TextContent), typeof(ImageContent), typeof(AudioContent), typeof(BinaryContent)\n};\nvar unsupported = history.SelectMany(m => m.Items)\n    .Where(item => !supportedTypes.Contains(item.GetType()))\n    .ToList();\nif (unsupported.Count > 0)\n{\n    throw new ArgumentException(\n        $\"Unsupported content types for Gemini: {string.Join(\", \", unsupported.Select(i => i.GetType().Name))}\");\n}","typeGuard":"static bool IsSupportedGeminiContent(KernelContent content) =>\n    content is TextContent or ImageContent or AudioContent or BinaryContent;","tryCatchPattern":"try { await client.GetChatMessageContentsAsync(history, settings, ct); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported content type\"))\n{\n    // Filter to supported types and retry\n    foreach (var msg in history)\n        msg.Items = msg.Items.Where(IsSupportedGeminiContent).ToList();\n    await client.GetChatMessageContentsAsync(history, settings, ct);\n}","preventionTips":["Only add TextContent, ImageContent, AudioContent, or BinaryContent to chat history for Gemini.","Handle function calls through the kernel plugin pipeline, not by manually adding FunctionCallContent to history.","Filter content before sending if the history may contain unsupported types from other connectors."],"tags":["google","gemini","content-type","notsupported","kernel-content"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}