{"record":{"id":"ebac3d61393402c2","repo":"microsoft/semantic-kernel","slug":"unsupported-content-type-content-gettype-name","errorCode":null,"errorMessage":"Unsupported content type {content.GetType().Name}. Cannot convert to ResponseContentPart.","messagePattern":"Unsupported content type (.+?)\\. Cannot convert to ResponseContentPart\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs","lineNumber":21,"sourceCode":"using System;\nusing OpenAI.Responses;\n\nnamespace Microsoft.SemanticKernel.Agents.OpenAI;\n\n/// <summary>\n/// Extensons methods for <see cref=\"KernelContent\"/>.\n/// </summary>\ninternal static class KernelContentExtensions\n{\n    internal static ResponseContentPart ToResponseContentPart(this KernelContent content)\n    {\n        return content switch\n        {\n            TextContent textContent => textContent.ToResponseContentPart(),\n            ImageContent imageContent => imageContent.ToResponseContentPart(),\n            BinaryContent binaryContent => binaryContent.ToResponseContentPart(),\n            FileReferenceContent fileReferenceContent => fileReferenceContent.ToResponseContentPart(),\n            _ => throw new NotSupportedException($\"Unsupported content type {content.GetType().Name}. Cannot convert to {nameof(ResponseContentPart)}.\")\n        };\n    }\n\n    internal static ResponseContentPart ToResponseContentPart(this TextContent content)\n    {\n        return ResponseContentPart.CreateInputTextPart(content.Text);\n    }\n\n    internal static ResponseContentPart ToResponseContentPart(this ImageContent content)\n    {\n        if (content.Uri is not null)\n        {\n            return ResponseContentPart.CreateInputImagePart(content.Uri);\n        }\n\n        if (content.Data is not null)\n        {\n            var dataUri = new Uri($\"data:{content.MimeType};base64,{Convert.ToBase64String(content.Data.Value.ToArray())}\");","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs#L3-L39","documentation":"KernelContentExtensions.ToResponseContentPart handles four KernelContent subtypes (TextContent, ImageContent, BinaryContent, FileReferenceContent). Any other KernelContent-derived type falls through the switch and throws NotSupportedException.","triggerScenarios":"A ChatMessageContent item is a content type the converter does not know, e.g., a custom KernelContent subclass or a content type added after this converter was written.","commonSituations":"Adding a custom content class to a message; version skew where a newer Semantic Kernel content type is not yet mapped; embedding an unsupported media type.","solutions":["Ensure every message item is one of TextContent, ImageContent, BinaryContent, or FileReferenceContent.","Project custom content into TextContent (e.g., serialize to text) before adding it to the message.","Upgrade the Agents.OpenAI package so newly supported content types are handled.","Unit-test message construction with the exact content types you will send."],"exampleFix":"// before\nmessage.Items.Add(myCustomContent);\n// after\nmessage.Items.Add(new TextContent(myCustomContent.ToString()));","handlingStrategy":"type-guard","validationCode":"static bool IsSupportedContent(KernelContent c) =>\n    c is TextContent or ImageContent or BinaryContent or FileReferenceContent;","typeGuard":"static bool IsSupportedContent(KernelContent c) =>\n    c is TextContent or ImageContent or BinaryContent or FileReferenceContent;","tryCatchPattern":"try { var part = content.ToResponseContentPart(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported content type\")) {\n    // project unknown content to TextContent instead\n}","preventionTips":["Construct messages only with the four supported content types.","Add a unit test asserting every message item passes the type guard.","Upgrade the Agents.OpenAI package when new content types are supported."],"tags":["openai","content","conversion","invalid-argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}