{"record":{"id":"c18584c735fde7fe","repo":"microsoft/semantic-kernel","slug":"imagecontent-cannot-be-converted-to-responseconten","errorCode":null,"errorMessage":"ImageContent cannot be converted to ResponseContentPart. Only ImageContent with a uri or binary data is supported.","messagePattern":"ImageContent cannot be converted to ResponseContentPart\\. Only ImageContent with a uri or binary data is supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs","lineNumber":43,"sourceCode":"    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())}\");\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":25,"sourceCodeEnd":60,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/Extensions/KernelContentExtensions.cs#L25-L60","documentation":"The ImageContent overload of ToResponseContentPart needs either a Uri or a Data payload to build an input-image part. If both are null, there is nothing to send and it throws NotSupportedException.","triggerScenarios":"Constructing ImageContent and adding it to a message without setting Uri or Data.","commonSituations":"Building ImageContent from metadata that omitted the source; loading an image that failed and left both fields null.","solutions":["Set ImageContent.Uri to a publicly reachable image URL, or set ImageContent.Data with a MimeType.","Validate the image source resolved before constructing ImageContent.","Skip the image item entirely when no source is available rather than passing an empty ImageContent."],"exampleFix":"// before\nvar img = new ImageContent();\nmessage.Items.Add(img);\n// after\nvar img = new ImageContent { Uri = new Uri(imageUrl) };\nmessage.Items.Add(img);","handlingStrategy":"validation","validationCode":"if (imageContent.Uri is null && imageContent.Data is null)\n    throw new ArgumentException(\"ImageContent must have a Uri or Data.\");","typeGuard":"static bool HasImageSource(ImageContent c) => c.Uri is not null || c.Data is not null;","tryCatchPattern":"try { var part = imageContent.ToResponseContentPart(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"ImageContent cannot be converted\")) {\n    // skip or supply a placeholder uri\n}","preventionTips":["Always set Uri or Data when creating ImageContent.","Validate image sources resolve before building content.","Centralize image-content construction in a helper that enforces the invariant."],"tags":["openai","image-content","invalid-argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}