iOfficeAI/OfficeCLI · error · ArgumentException
Invalid data URI: missing comma separator
Error message
Invalid data URI: missing comma separator
What it means
Thrown by FileSource.ResolveDataUri when a data: URI has no comma separating the header from the payload. RFC 2397 data URIs are shaped 'data:[<mediatype>][;base64],<data>'; without the comma the payload cannot be located.
Source
Thrown at src/officecli/Core/FileSource.cs:132
// Try extension from URL path
var uri = new Uri(url);
var ext = Path.GetExtension(uri.AbsolutePath).ToLowerInvariant();
// Fallback: infer from content-type header
if (string.IsNullOrEmpty(ext))
{
var mime = response.Content.Headers.ContentType?.MediaType;
ext = MimeToExtension(mime);
}
return (new MemoryStream(bytes), ext);
}
private static (MemoryStream, string) ResolveDataUri(string dataUri)
{
var commaIdx = dataUri.IndexOf(',');
if (commaIdx < 0)
throw new ArgumentException("Invalid data URI: missing comma separator");
var header = dataUri[..commaIdx];
var data = dataUri[(commaIdx + 1)..];
if (!header.Contains("base64", StringComparison.OrdinalIgnoreCase))
throw new ArgumentException("Only base64-encoded data URIs are supported");
var mimeStart = header.IndexOf(':') + 1;
var mimeEnd = header.IndexOf(';');
var mime = mimeEnd > mimeStart ? header[mimeStart..mimeEnd] : header[mimeStart..];
var ext = MimeToExtension(mime);
return (new MemoryStream(Convert.FromBase64String(data)), ext);
}
private static string MimeToExtension(string? mime)
{
if (string.IsNullOrEmpty(mime)) return "";View on GitHub (pinned to 1ced45e900)
Solutions
- Ensure the data URI is well-formed: data:<mime>;base64,<payload>.
- Use a URI/data-URI builder rather than hand-concatenating.
- If you only have raw base64, add the proper 'data:<mime>;base64,' prefix including the comma.
Example fix
// before
FileSource.Resolve("data:image/png;base64"); // missing ,<payload>
// after
FileSource.Resolve($"data:image/png;base64,{base64Payload}"); Defensive patterns
Strategy: validation
Validate before calling
static bool IsPlausibleDataUri(string s) =>
s.StartsWith("data:", StringComparison.OrdinalIgnoreCase) && s.Contains(','); Type guard
static bool LooksLikeDataUri(string s) => s.StartsWith("data:", StringComparison.OrdinalIgnoreCase) && s.IndexOf(',') > 4; Try / catch
try { var r = FileSource.Resolve(dataUri); }
catch (ArgumentException ex) when (ex.Message.Contains("missing comma separator"))
{ /* rebuild the data URI with a proper header+comma */ } Prevention
- Build data URIs with a helper, not string concatenation.
- Always include the ',' before the payload.
When it happens
Trigger: Calling FileSource.Resolve with a string starting with 'data:' (case-insensitive) that contains no ',' character. IndexOf(',') returns -1 and the guard throws.
Common situations: Truncated/pasted data URI missing the payload; a data: URL built by string concatenation that dropped the comma; a base64 string passed without the data: prefix wrapper correctly.
Related errors
- Only base64-encoded data URIs are supported
- File source cannot be empty
- Invalid data URI: missing comma separator
- Only base64-encoded data URIs are supported
- Invalid data URI: empty base64 payload (would produce a 0-by
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/54f697bee0df169a.
Report an issue: GitHub.