{"record":{"id":"2b735c6a07bd7671","repo":"microsoft/semantic-kernel","slug":"audiocontent-cannot-be-converted-to-responseconten","errorCode":null,"errorMessage":"AudioContent cannot be converted to ResponseContentPart. Only AudioContent with binary data is supported.","messagePattern":"AudioContent cannot be converted to ResponseContentPart\\. Only AudioContent with binary data is supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs","lineNumber":50,"sourceCode":"        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())}\");\n            return ResponseContentPart.CreateInputImagePart(dataUri);\n        }\n\n        throw new NotSupportedException(\"ImageContent cannot be converted to ResponseContentPart. Only ImageContent with a uri or binary data is supported.\");\n    }\n\n    internal static ResponseContentPart ToResponseContentPart(this BinaryContent content)\n    {\n        return content.Data is not null\n            ? ResponseContentPart.CreateInputFilePart(new BinaryData(content.Data), content.MimeType, Guid.NewGuid().ToString())\n            : throw new NotSupportedException(\"AudioContent cannot be converted to ResponseContentPart. Only AudioContent with binary data is supported.\");\n    }\n\n    internal static ResponseContentPart ToResponseContentPart(this FileReferenceContent content)\n    {\n        return content.FileId is not null\n            ? ResponseContentPart.CreateInputFilePart(content.FileId)\n            : throw new NotSupportedException(\"FileReferenceContent cannot be converted to ResponseContentPart. Only FileReferenceContent with a file id is supported.\");\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":60,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs#L32-L60","documentation":"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.","triggerScenarios":"Adding a BinaryContent (used for audio and other binary) to a message without setting its Data.","commonSituations":"Creating audio/binary content from a stream that was empty or never read; deserialized content that lost its Data.","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."],"exampleFix":"// before\nvar audio = new BinaryContent(mimeType: \"audio/wav\");\nmessage.Items.Add(audio);\n// after\nvar audio = BinaryContent.Create(dataBytes, \"audio/wav\");\nmessage.Items.Add(audio);","handlingStrategy":"validation","validationCode":"if (binaryContent.Data is null)\n    throw new ArgumentException(\"BinaryContent (audio) must have Data.\");","typeGuard":"static bool HasBinaryData(BinaryContent c) => c.Data is not null;","tryCatchPattern":"try { var part = binaryContent.ToResponseContentPart(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"AudioContent cannot be converted\")) {\n    // load the byte stream before retrying, or skip the item\n}","preventionTips":["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."],"tags":["openai","binary-content","audio-content","invalid-argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}