microsoft/semantic-kernel · error · NotSupportedException
Unsupported content type {content.GetType().Name}. Cannot co
Error message
Unsupported content type {content.GetType().Name}. Cannot convert to ResponseContentPart. What it means
KernelContentExtensions.ToResponseContentPart handles four KernelContent subtypes (TextContent, ImageContent, BinaryContent, FileReferenceContent). Any other KernelContent-derived type falls through the switch and throws NotSupportedException.
Source
Thrown at dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs:21
using System;
using OpenAI.Responses;
namespace Microsoft.SemanticKernel.Agents.OpenAI;
/// <summary>
/// Extensons methods for <see cref="KernelContent"/>.
/// </summary>
internal static class KernelContentExtensions
{
internal static ResponseContentPart ToResponseContentPart(this KernelContent content)
{
return content switch
{
TextContent textContent => textContent.ToResponseContentPart(),
ImageContent imageContent => imageContent.ToResponseContentPart(),
BinaryContent binaryContent => binaryContent.ToResponseContentPart(),
FileReferenceContent fileReferenceContent => fileReferenceContent.ToResponseContentPart(),
_ => throw new NotSupportedException($"Unsupported content type {content.GetType().Name}. Cannot convert to {nameof(ResponseContentPart)}.")
};
}
internal static ResponseContentPart ToResponseContentPart(this TextContent content)
{
return ResponseContentPart.CreateInputTextPart(content.Text);
}
internal static ResponseContentPart ToResponseContentPart(this ImageContent content)
{
if (content.Uri is not null)
{
return ResponseContentPart.CreateInputImagePart(content.Uri);
}
if (content.Data is not null)
{
var dataUri = new Uri($"data:{content.MimeType};base64,{Convert.ToBase64String(content.Data.Value.ToArray())}");View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before message.Items.Add(myCustomContent); // after message.Items.Add(new TextContent(myCustomContent.ToString()));
Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSupportedContent(KernelContent c) =>
c is TextContent or ImageContent or BinaryContent or FileReferenceContent; Type guard
static bool IsSupportedContent(KernelContent c) =>
c is TextContent or ImageContent or BinaryContent or FileReferenceContent; Try / catch
try { var part = content.ToResponseContentPart(); }
catch (NotSupportedException ex) when (ex.Message.Contains("Unsupported content type")) {
// project unknown content to TextContent instead
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid OpenAI client type '{connection.Type}' was specified
- Unsupported role {message.Role.Label}. Only system, user, de
- ImageContent cannot be converted to ResponseContentPart. Onl
- AudioContent cannot be converted to ResponseContentPart. Onl
- FileReferenceContent cannot be converted to ResponseContentP
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ebac3d61393402c2.
Report an issue: GitHub.