microsoft/semantic-kernel · error · NotSupportedException
AudioContent cannot be converted to ResponseContentPart. Onl
Error message
AudioContent cannot be converted to ResponseContentPart. Only AudioContent with binary data is supported.
What it means
The BinaryContent overload of ToResponseContentPart requires content.Data to build an input-file part; if Data is null it throws. Note: the message text says 'AudioContent' but the method handles BinaryContent (a copy-paste mismatch), so this covers audio/binary content without a data payload.
Source
Thrown at dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs:50
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())}");
return ResponseContentPart.CreateInputImagePart(dataUri);
}
throw new NotSupportedException("ImageContent cannot be converted to ResponseContentPart. Only ImageContent with a uri or binary data is supported.");
}
internal static ResponseContentPart ToResponseContentPart(this BinaryContent content)
{
return content.Data is not null
? ResponseContentPart.CreateInputFilePart(new BinaryData(content.Data), content.MimeType, Guid.NewGuid().ToString())
: throw new NotSupportedException("AudioContent cannot be converted to ResponseContentPart. Only AudioContent with binary data is supported.");
}
internal static ResponseContentPart ToResponseContentPart(this FileReferenceContent content)
{
return content.FileId is not null
? ResponseContentPart.CreateInputFilePart(content.FileId)
: throw new NotSupportedException("FileReferenceContent cannot be converted to ResponseContentPart. Only FileReferenceContent with a file id is supported.");
}
}
View on GitHub (pinned to c028a0c7dc)
Solutions
- Populate BinaryContent.Data from a valid byte stream before adding to the message.
- Verify the underlying stream/file is non-empty before constructing the content.
- Drop the item if no binary payload is available.
Example fix
// before var audio = new BinaryContent(mimeType: "audio/wav"); message.Items.Add(audio); // after var audio = BinaryContent.Create(dataBytes, "audio/wav"); message.Items.Add(audio);
Defensive patterns
Strategy: validation
Validate before calling
if (binaryContent.Data is null)
throw new ArgumentException("BinaryContent (audio) must have Data."); Type guard
static bool HasBinaryData(BinaryContent c) => c.Data is not null;
Try / catch
try { var part = binaryContent.ToResponseContentPart(); }
catch (NotSupportedException ex) when (ex.Message.Contains("AudioContent cannot be converted")) {
// load the byte stream before retrying, or skip the item
} Prevention
- Read the underlying stream fully before constructing BinaryContent.
- Verify audio file size > 0 before loading.
- Note the message text says 'AudioContent' but the method handles BinaryContent.
When it happens
Trigger: Adding a BinaryContent (used for audio and other binary) to a message without setting its Data.
Common situations: Creating audio/binary content from a stream that was empty or never read; deserialized content that lost its Data.
Related errors
- Invalid OpenAI client type '{connection.Type}' was specified
- Unsupported role {message.Role.Label}. Only system, user, de
- Unsupported content type {content.GetType().Name}. Cannot co
- ImageContent 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/2b735c6a07bd7671.
Report an issue: GitHub.