{"record":{"id":"9ac99da08c0e7518","repo":"microsoft/semantic-kernel","slug":"geminipart-is-invalid-one-and-only-one-property-a","errorCode":null,"errorMessage":"GeminiPart is invalid. One and only one property among Text, InlineData, FileData, FunctionCall, and FunctionResponse should be set.","messagePattern":"GeminiPart is invalid\\. One and only one property among Text, InlineData, FileData, FunctionCall, and FunctionResponse should be set\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiPart.cs","lineNumber":89,"sourceCode":"    /// Checks whether only one property of the GeminiPart instance is not null.\n    /// Returns true if only one property among Text, InlineData, FileData, FunctionCall, and FunctionResponse is not null,\n    /// Otherwise, it returns false.\n    /// </summary>\n    public bool IsValid()\n    {\n        return (this.Text is not null ? 1 : 0) +\n            (this.InlineData is not null ? 1 : 0) +\n            (this.FileData is not null ? 1 : 0) +\n            (this.FunctionCall is not null ? 1 : 0) +\n            (this.FunctionResponse is not null ? 1 : 0) == 1;\n    }\n\n    /// <inheritdoc />\n    public void OnDeserialized()\n    {\n        if (!this.IsValid())\n        {\n            throw new JsonException(\n                \"GeminiPart is invalid. One and only one property among Text, InlineData, FileData, FunctionCall, and FunctionResponse should be set.\");\n        }\n    }\n\n    /// <summary>\n    /// Inline media bytes like image or video data.\n    /// </summary>\n    internal sealed class InlineDataPart\n    {\n        /// <summary>\n        /// The IANA standard MIME type of the source data.\n        /// </summary>\n        /// <remarks>\n        /// Acceptable values include: \"image/png\", \"image/jpeg\", \"image/heic\", \"image/heif\", \"image/webp\".\n        /// </remarks>\n        [JsonPropertyName(\"mimeType\")]\n        [JsonRequired]\n        public string MimeType { get; set; } = null!;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Google/Core/Gemini/Models/GeminiPart.cs#L71-L107","documentation":"Thrown by GeminiPart.OnDeserialized (an IJsonOnDeserialized callback) when a deserialized GeminiPart does not have exactly one of its five union properties set (Text, InlineData, FileData, FunctionCall, FunctionResponse). The IsValid() method counts non-null properties among these five and requires the total to be exactly 1. Note: Thought and ThoughtSignature are NOT counted — a part can have Thought=true alongside exactly one content property.","triggerScenarios":"A Gemini API response contains a 'parts' array entry where zero or more than one of the five content fields is populated. This fires automatically after System.Text.Json finishes deserializing each GeminiPart instance, before the connector processes it.","commonSituations":"Google's API response format changes to include a part with multiple content fields. A mock/test server returns malformed parts. An API error response that partially matches the GeminiResponse schema but has incomplete or malformed parts. Google introduces a new content field that co-exists with an existing one.","solutions":["This is almost always a response-parsing issue, not a caller error — check the raw API response.","Upgrade the Connectors.Google package to match the API version.","If mocking Gemini responses in tests, ensure each part has exactly one content field.","Catch JsonException around Gemini calls and log the response for diagnosis."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { var response = await client.GetChatMessageContentsAsync(history, settings, ct); }\ncatch (JsonException ex) when (ex.Message.Contains(\"GeminiPart is invalid\"))\n{\n    logger.LogError(ex, \"Gemini returned a part with invalid structure. \" +\n        \"Possible API version mismatch. Enable response logging for details.\");\n    throw;\n}","preventionTips":["This is a response-side error typically caused by API version mismatches; keep the connector package up to date.","When mocking Gemini responses in tests, ensure each part has exactly one content property (Text, InlineData, FileData, FunctionCall, or FunctionResponse).","Enable debug logging on the Google connector to capture raw responses for diagnosis."],"tags":["google","gemini","json","deserialization","validation","model-validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}