{"record":{"id":"aedf0883b9a6a23d","repo":"microsoft/semantic-kernel","slug":"binary-content-mimetype-is-empty","errorCode":null,"errorMessage":"Binary content MimeType is empty.","messagePattern":"Binary content MimeType is empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs","lineNumber":422,"sourceCode":"        if (binaryContent.Uri is not null)\n        {\n            return new GeminiPart\n            {\n                FileData = new GeminiPart.FileDataPart\n                {\n                    MimeType = GetMimeTypeFromBinaryContent(binaryContent),\n                    FileUri = binaryContent.Uri ?? throw new InvalidOperationException(\"Binary content URI is empty.\")\n                }\n            };\n        }\n\n        throw new InvalidOperationException(\"Binary content does not contain any data or uri.\");\n    }\n\n    private static string GetMimeTypeFromBinaryContent(BinaryContent binaryContent)\n    {\n        return binaryContent.MimeType\n               ?? throw new InvalidOperationException(\"Binary content MimeType is empty.\");\n    }\n\n    private static void AddConfiguration(GeminiPromptExecutionSettings executionSettings, GeminiRequest request)\n    {\n        request.Configuration = new ConfigurationElement\n        {\n            Temperature = executionSettings.Temperature,\n            TopP = executionSettings.TopP,\n            TopK = executionSettings.TopK,\n            MaxOutputTokens = executionSettings.MaxTokens,\n            StopSequences = executionSettings.StopSequences,\n            CandidateCount = executionSettings.CandidateCount,\n            AudioTimestamp = executionSettings.AudioTimestamp,\n            ResponseMimeType = executionSettings.ResponseMimeType,\n            ResponseSchema = GetResponseSchemaConfig(executionSettings.ResponseSchema),\n        };\n    }\n","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs#L404-L440","documentation":"Thrown by GetMimeTypeFromBinaryContent when binaryContent.MimeType is null. Gemini requires an explicit MIME type for both inline and file-URI binary parts. Fires on both code paths because GetMimeTypeFromBinaryContent is invoked in each branch of CreateGeminiPartFromBinary.","triggerScenarios":"Constructing a BinaryContent with Data or a Uri but without setting MimeType, then passing it to a Gemini chat request.","commonSituations":"Passing raw bytes without inferring the format; HTTP downloads where the content-type header was dropped; generic byte loaders that leave MimeType unset.","solutions":["Always set MimeType when constructing BinaryContent (e.g. \"application/pdf\", \"image/png\").","Derive it from the source file extension or HTTP Content-Type header.","Validate MimeType is non-null before adding the content to ChatHistory."],"exampleFix":"// before\nvar bin = new BinaryContent(bytes);  // MimeType null\n\n// after\nvar bin = new BinaryContent(bytes, mimeType: \"application/pdf\");","handlingStrategy":"validation","validationCode":"static void EnsureBinaryMime(BinaryContent c)\n{\n    if (string.IsNullOrWhiteSpace(c.MimeType))\n        throw new InvalidOperationException(\"BinaryContent.MimeType is required for Gemini.\");\n}","typeGuard":"static bool HasBinaryMime(BinaryContent c) => !string.IsNullOrWhiteSpace(c.MimeType);","tryCatchPattern":"try { await kernel.InvokePromptAsync(prompt); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Binary content MimeType is empty.\"))\n{ logger.LogError(ex, \"Set BinaryContent.MimeType before sending.\"); throw; }","preventionTips":["Always set a mime type when constructing BinaryContent.","Infer mime from file extension or HTTP Content-Type.","Centralize construction in a helper enforcing non-null mime."],"tags":["gemini","binary","mime-type","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}