{"record":{"id":"e118d8a41f9f4d53","repo":"microsoft/semantic-kernel","slug":"audio-content-mimetype-is-empty","errorCode":null,"errorMessage":"Audio content MimeType is empty.","messagePattern":"Audio content MimeType is empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs","lineNumber":386,"sourceCode":"        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),\n                    InlineData = Convert.ToBase64String(binaryContent.Data.Value.ToArray())\n                }\n            };\n        }\n\n        if (binaryContent.Uri is not null)","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs#L368-L404","documentation":"Thrown by GetMimeTypeFromAudioContent when audioContent.MimeType is null. Gemini requires an explicit MIME type for both inline data and file-URI audio parts, so the connector refuses to serialize audio without one. This fires on BOTH the inline-data and file-URI code paths because GetMimeTypeFromAudioContent is called in each branch.","triggerScenarios":"Adding an AudioContent to a Gemini chat history without setting MimeType, regardless of whether Data or Uri is populated. Also fires when constructing audio from a raw byte array without specifying the mime type.","commonSituations":"Inferring a file's format by extension locally but forgetting to pass the mime type to AudioContent; loading bytes without a content-type header; generic media loaders that leave MimeType null.","solutions":["Always set MimeType (e.g. \"audio/wav\", \"audio/mp3\", \"audio/aac\") when constructing AudioContent.","If loading from an HTTP response, use response.Content.Headers.ContentType.MediaType.","Map the file extension to a mime type before constructing the content."],"exampleFix":"// before\nvar audio = new AudioContent(bytes);  // MimeType null\n\n// after\nvar audio = new AudioContent(bytes, mimeType: \"audio/wav\");","handlingStrategy":"validation","validationCode":"static void EnsureAudioMime(AudioContent c)\n{\n    if (string.IsNullOrWhiteSpace(c.MimeType))\n        throw new InvalidOperationException(\"AudioContent.MimeType is required for Gemini.\");\n}","typeGuard":"static bool HasAudioMime(AudioContent c) => !string.IsNullOrWhiteSpace(c.MimeType);","tryCatchPattern":"try { await kernel.InvokePromptAsync(prompt); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Audio content MimeType is empty.\"))\n{ logger.LogError(ex, \"Set AudioContent.MimeType before sending.\"); throw; }","preventionTips":["Always pass a mime type when constructing AudioContent.","Derive mime from the file extension or HTTP Content-Type header.","Centralize content construction in a helper that enforces non-null mime."],"tags":["gemini","audio","mime-type","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}