{"record":{"id":"6d497a08e1270699","repo":"microsoft/semantic-kernel","slug":"image-content-uri-is-empty","errorCode":null,"errorMessage":"Image content URI is empty.","messagePattern":"Image content URI is empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs","lineNumber":308,"sourceCode":"        {\n            return new GeminiPart\n            {\n                InlineData = new GeminiPart.InlineDataPart\n                {\n                    MimeType = GetMimeTypeFromImageContent(imageContent),\n                    InlineData = Convert.ToBase64String(imageContent.Data.Value.ToArray())\n                }\n            };\n        }\n\n        if (imageContent.Uri is not null)\n        {\n            return new GeminiPart\n            {\n                FileData = new GeminiPart.FileDataPart\n                {\n                    MimeType = GetMimeTypeFromImageContent(imageContent),\n                    FileUri = imageContent.Uri ?? throw new InvalidOperationException(\"Image content URI is empty.\")\n                }\n            };\n        }\n\n        throw new InvalidOperationException(\"Image content does not contain any data or uri.\");\n    }\n\n    private static string GetMimeTypeFromImageContent(ImageContent imageContent)\n    {\n        return imageContent.MimeType\n               ?? throw new InvalidOperationException(\"Image content MimeType is empty.\");\n    }\n\n    /// <summary>\n    /// Creates a GeminiPart with FunctionResponse containing multimodal image data (Gemini 3+ only).\n    /// </summary>\n    private static GeminiPart CreateImageFunctionResponsePart(string functionName, ImageContent imageContent)\n    {","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiRequest.cs#L290-L326","documentation":"Declared in GeminiRequest.CreateGeminiPartFromImage inside the 'if (imageContent.Uri is not null)' branch as 'imageContent.Uri ?? throw new InvalidOperationException(...)'. This throw is DEAD CODE: the enclosing if-statement already guarantees imageContent.Uri is not null, so the null-coalescing operator's right-hand side can never execute. The throw cannot fire under any circumstance. If it theoretically could, it would mean the Uri property has race-condition semantics (returned non-null for the 'is' check but null for the ?? operator).","triggerScenarios":"This exception is unreachable in practice. The code path requires imageContent.Uri to be non-null (checked by the if-condition) and then uses '?? throw' on the same property, which is logically contradictory. No caller input can trigger it without the ImageContent.Uri property having side-effectful or non-deterministic behavior between calls.","commonSituations":"This is a code-level defensive check that is logically impossible to trigger given the surrounding control flow. It may represent a copy-paste pattern or defensive coding habit. Developers reading this should not expect to ever see this exception at runtime.","solutions":["No action needed — this throw cannot fire. If you believe you are hitting this error, check the stack trace to confirm the actual source.","The real error users hit when an ImageContent lacks data AND uri is error 337 ('Image content does not contain any data or uri.')."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// This error is unreachable (dead code). No validation is needed.\n// The real concern is error 337 (no data and no uri).\n// Validate ImageContent properly:\nif (image.Data is null or { IsEmpty: true } && image.Uri is null)\n    throw new ArgumentException(\"ImageContent must have Data or Uri.\");","typeGuard":"null","tryCatchPattern":"null","preventionTips":["This exception is dead code — it cannot fire because the enclosing if-statement already checks Uri is not null.","If you see an image-related error, check for error 337 or 338 instead."],"tags":["google","gemini","dead-code","image-content","code-smell"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}