{"record":{"id":"39cb898e7a99062a","repo":"microsoft/autogen","slug":"invalid-imagemessage-the-data-or-url-must-be-prov-39cb89","errorCode":null,"errorMessage":"Invalid ImageMessage, the data or url must be provided","messagePattern":"Invalid ImageMessage, the data or url must be provided","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs","lineNumber":470,"sourceCode":"                    FileUri = url,\n                    MimeType = message.MimeType\n                }\n            };\n        }\n        else if (message.Data is BinaryData data)\n        {\n            return new Part\n            {\n                InlineData = new Blob\n                {\n                    MimeType = message.MimeType,\n                    Data = ByteString.CopyFrom(data.ToArray()),\n                }\n            };\n        }\n        else\n        {\n            throw new InvalidOperationException(\"Invalid ImageMessage, the data or url must be provided\");\n        }\n    }\n\n    private bool ShouldParseAsUser(IMessage message, IAgent agent)\n    {\n        return message switch\n        {\n            TextMessage textMessage => (textMessage.Role == Role.User && textMessage.From is null)\n                || (textMessage.From != agent.Name),\n            _ => message.From != agent.Name,\n        };\n    }\n}\n","sourceCodeStart":452,"sourceCodeEnd":484,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Gemini/Middleware/GeminiMessageConnector.cs#L452-L484","documentation":"GeminiMessageConnector.CreateImagePart builds an inline Gemini Blob from an ImageMessage. It supports raw bytes (message.Data) and downloads from a URL; if the message has neither usable data nor a resolvable URL, it throws this InvalidOperationException because no Part can be produced.","triggerScenarios":"Constructing ImageMessage with both Data and Url null/empty (e.g. default constructor or factory that failed to load the image), or a Url that yields an empty/failed download so no byte array was obtained.","commonSituations":"Image-loading code that swallows exceptions and still creates the message; URL fetch blocked by network/404 leaving data null; refactoring that dropped the Data assignment.","solutions":["Verify ImageMessage.Data is non-empty before sending, or set a valid Url.","If using Url, confirm it is publicly reachable (200, image content) — the connector fetches it server-side.","Add a guard in your message-factory: skip/throw early when both fields are empty so the failure points at the loader, not the connector."],"exampleFix":"// before\nvar img = new ImageMessage(Role.User, mimeType: \"image/png\"); // no data, no url\n\n// after\nvar img = new ImageMessage(Role.User, mimeType: \"image/png\", data: await File.ReadAllBytesAsync(\"chart.png\"));","handlingStrategy":"validation","validationCode":"if (imageMessage.Data is null || imageMessage.Data.Length == 0 && string.IsNullOrEmpty(imageMessage.Url?.ToString()))\n{\n    throw new ArgumentException(\"ImageMessage needs Data or Url\", nameof(imageMessage));\n}","typeGuard":"static bool HasImagePayload(ImageMessage m) => (m.Data is { Length: > 0 }) || !string.IsNullOrEmpty(m.Url?.ToString());","tryCatchPattern":null,"preventionTips":["Load image bytes before constructing the message","Fail loudly in image loaders instead of emitting empty messages","Verify URLs are fetchable when using Url mode"],"tags":["gemini","image-message","validation","invalid-operation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}