{"record":{"id":"009efb8ac60c15c7","repo":"microsoft/semantic-kernel","slug":"audio-content-does-not-contain-any-data-or-uri","errorCode":null,"errorMessage":"Audio content does not contain any data or uri.","messagePattern":"Audio content does not contain any data or uri\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs","lineNumber":380,"sourceCode":"                    MimeType = GetMimeTypeFromAudioContent(audioContent),\n                    InlineData = Convert.ToBase64String(audioContent.Data.Value.ToArray())\n                }\n            };\n        }\n\n        if (audioContent.Uri is not null)\n        {\n            return new GeminiPart\n            {\n                FileData = new GeminiPart.FileDataPart\n                {\n                    MimeType = GetMimeTypeFromAudioContent(audioContent),\n                    FileUri = audioContent.Uri ?? throw new InvalidOperationException(\"Audio content URI is empty.\")\n                }\n            };\n        }\n\n        throw new InvalidOperationException(\"Audio content does not contain any data or uri.\");\n    }\n\n    private static string GetMimeTypeFromAudioContent(AudioContent audioContent)\n    {\n        return audioContent.MimeType\n               ?? throw new InvalidOperationException(\"Audio content MimeType is empty.\");\n    }\n\n    private static GeminiPart CreateGeminiPartFromBinary(BinaryContent binaryContent)\n    {\n        // Binary data takes precedence over URI.\n        if (binaryContent.Data is { IsEmpty: false })\n        {\n            return new GeminiPart\n            {\n                InlineData = new GeminiPart.InlineDataPart\n                {\n                    MimeType = GetMimeTypeFromBinaryContent(binaryContent),","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs#L362-L398","documentation":"Thrown by CreateGeminiPartFromAudio when an AudioContent has neither usable binary Data (null or empty) nor a Uri. The connector cannot build a Gemini part because Gemini needs either inline base64 bytes or a file URI. This is the terminal fallback after both branches are skipped.","triggerScenarios":"Constructing an AudioContent and adding it to a chat history without populating Data or Uri; e.g. new AudioContent() with defaults, or an AudioContent whose stream failed to load so Data stayed null/empty.","commonSituations":"Loading an audio file from a path that does not exist or fails silently; deserializing an AudioContent from JSON that omits both data and uri; a helper that creates a placeholder AudioContent before the real bytes are attached.","solutions":["Ensure the AudioContent has either Data set (read the file bytes/stream into it) or a Uri set before adding it to ChatHistory.","Check audioContent.Data is non-null/non-empty or audioContent.Uri is non-null before invoking the kernel.","Verify the source file path/URL exists and is readable when loading audio content."],"exampleFix":"// before\nvar audio = new AudioContent();  // no data, no uri\nhistory.AddUserMessage(audio);\n\n// after\nvar bytes = await File.ReadAllBytesAsync(\"clip.wav\");\nvar audio = new AudioContent(bytes, mimeType: \"audio/wav\");\n// or: var audio = new AudioContent(uri: \"https://.../clip.wav\", mimeType: \"audio/wav\");\nhistory.AddUserMessage(audio);","handlingStrategy":"validation","validationCode":"static void EnsureAudioUsable(AudioContent c)\n{\n    if ((c.Data is null || c.Data.Value.IsEmpty) && c.Uri is null)\n        throw new InvalidOperationException(\"AudioContent needs Data or Uri before sending to Gemini.\");\n}","typeGuard":"static bool HasAudioPayload(AudioContent c)\n    => (c.Data is { IsEmpty: false }) || c.Uri is not null;","tryCatchPattern":"try { await kernel.InvokePromptAsync(prompt); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Audio content does not contain any data or uri.\"))\n{ logger.LogError(ex, \"AudioContent was empty; attach data or a URI.\"); throw; }","preventionTips":["Always load audio bytes or set a URI before adding AudioContent to ChatHistory.","Verify the source file/URL exists and is readable.","Unit-test content construction paths to assert Data or Uri is set."],"tags":["gemini","audio","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}