{"record":{"id":"01178eb671947ef9","repo":"microsoft/autogen","slug":"data-cannot-be-empty","errorCode":null,"errorMessage":"Data cannot be empty","messagePattern":"Data cannot be empty","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Core/Message/ImageMessage.cs","lineNumber":70,"sourceCode":"                    _ when url.EndsWith(\".svg\", StringComparison.OrdinalIgnoreCase) => \"image/svg+xml\",\n                    _ => throw new ArgumentException(\"MimeType is required for ImageMessage\", nameof(mimeType))\n                };\n            }\n\n            this.MimeType = mimeType;\n        }\n    }\n\n    public ImageMessage(Role role, Uri uri, string? from = null, string? mimeType = null)\n        : this(role, uri.ToString(), from, mimeType)\n    {\n    }\n\n    public ImageMessage(Role role, BinaryData data, string? from = null)\n    {\n        if (data.IsEmpty)\n        {\n            throw new ArgumentException(\"Data cannot be empty\", nameof(data));\n        }\n\n        if (data.MediaType is null)\n        {\n            throw new ArgumentException(\"MediaType is needed for DataUri Images\", nameof(data));\n        }\n\n        this.Role = role;\n        this.From = from;\n        this.Data = data;\n        this.MimeType = data.MediaType;\n    }\n\n    public Role Role { get; }\n\n    public string? Url { get; }\n\n    public string? From { get; set; }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Core/Message/ImageMessage.cs#L52-L88","documentation":"The BinaryData overload of ImageMessage rejects empty payloads: if data.IsEmpty is true it throws ArgumentException('Data cannot be empty', paramName: data). BinaryData.IsEmpty is true for zero-length buffers, so constructing an image message with no bytes (e.g. an empty file read or an empty memory stream) fails immediately.","triggerScenarios":"new ImageMessage(role, new BinaryData(Array.Empty<byte>(), \"image/png\")); reading a zero-byte file with File.ReadAllBytesAsync and wrapping it; uploading from a stream that was already consumed or never written.","commonSituations":"Failed downloads or empty attachments upstream in the pipeline; race conditions where a file is read before being written; placeholder code creating BinaryData from empty arrays during development.","solutions":["Verify the byte array length is > 0 before constructing the message.","Check file/stream length and log a clear error when the source produced zero bytes.","Fix the upstream producer (download, screenshot capture, file write) that yielded the empty payload."],"exampleFix":"// before\nvar bytes = await File.ReadAllBytesAsync(path); // zero-byte file\nvar msg = new ImageMessage(Role.User, new BinaryData(bytes, \"image/png\")); // throws\n\n// after\nvar bytes = await File.ReadAllBytesAsync(path);\nif (bytes.Length == 0) throw new InvalidDataException($\"{path} is empty\");\nvar msg = new ImageMessage(Role.User, new BinaryData(bytes, \"image/png\"));","handlingStrategy":"validation","validationCode":"if (bytes is null || bytes.Length == 0)\n    throw new InvalidDataException(\"Image payload is empty; check the upstream producer\");\nvar msg = new ImageMessage(Role.User, new BinaryData(bytes, \"image/png\"));","typeGuard":"static bool HasImagePayload(BinaryData data) => !data.IsEmpty;","tryCatchPattern":"try { var msg = new ImageMessage(Role.User, data); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Data cannot be empty\"))\n{\n    // re-fetch or regenerate the image, then retry\n}","preventionTips":["Check byte-array length before wrapping in BinaryData.","Validate file sizes after download; treat 0-byte results as upstream failures.","Add logging at image-acquisition boundaries to catch empty captures early."],"tags":["autogen","dotnet","message","image-message","binary-data","validation","argumentexception"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}