iOfficeAI/OfficeCLI · error · ArgumentException
Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
Error message
Invalid color value: '{value}'. Expected 6-digit hex RGB (e.g. FF0000), 8-digit AARRGGBB (e.g. 80FF0000), 3-digit shorthand (e.g. F00) or 4-digit #RGBA shorthand (e.g. F00A), named color (e.g. red), rgb()/rgba()/hsl()/hsla() notation, or 'transparent'. What it means
Thrown by ParseHelpers.NormalizeArgbColor as the final fallthrough when the input matches none of the accepted color forms. The function returns an 8-char AARRGGBB string and accepts: named colors, rgb()/rgba()/hsl()/hsla(), 'transparent', 6-hex RGB, 8-hex AARRGGBB (or #RRGGBBAA), 3-hex shorthand, and #RGBA shorthand (non-zero alpha). Inner whitespace and any other shape are rejected.
Source
Thrown at src/officecli/Core/ParseHelpers.cs:602
// (the explicit `transparent` keyword or 8-digit #00000000 form
// exists for that intent and is unambiguous).
hex = new string(new[]
{
hex[0], hex[0], hex[1], hex[1], hex[2], hex[2], hex[3], hex[3],
});
}
if (hex.Length == 6 && hex.All(char.IsAsciiHexDigit))
return "FF" + hex;
if (hex.Length == 8 && hex.All(char.IsAsciiHexDigit))
{
// CONSISTENCY(color-input-form): #-prefixed 8-hex is CSS RRGGBBAA
// (alpha last); bare 8-hex stays in OOXML AARRGGBB (alpha first).
// Mirrors SanitizeColorForOoxml.
if (hadHashPrefix)
return hex.Substring(6, 2) + hex[..6];
return hex;
}
throw new ArgumentException(
$"Invalid color value: '{value}'. Expected 6-digit hex RGB (e.g. FF0000), " +
$"8-digit AARRGGBB (e.g. 80FF0000), 3-digit shorthand (e.g. F00) or 4-digit #RGBA shorthand (e.g. F00A), " +
$"named color (e.g. red), rgb()/rgba()/hsl()/hsla() notation, or 'transparent'.");
}
/// <summary>
/// Word/PPT theme scheme color names (ECMA-376 §17.18.97 / §20.1.10.46).
/// Keep lowercase — input is matched case-insensitively but the canonical
/// OOXML serialization (and downstream readback) is lowercase.
/// </summary>
public static readonly HashSet<string> SchemeColorNames = new(StringComparer.OrdinalIgnoreCase)
{
"dark1", "light1", "dark2", "light2",
"accent1", "accent2", "accent3", "accent4", "accent5", "accent6",
"hyperlink", "followedHyperlink",
// Extra variants seen in OOXML: text1/text2/background1/background2 alias dark/light.
"text1", "text2", "background1", "background2",
// BUG-R6-06: alternate Word theme color aliases (windowText / windowBackground)View on GitHub (pinned to 1ced45e900)
Solutions
- Use a supported literal form: 'FF0000', '#FF0000', 'F00', '80FF0000', '#FF0000AA', 'red', 'rgb(255,0,0)', 'transparent'.
- For scheme/theme colors (accent1, dark2, hyperlink, …) use a property that accepts theme colors — NormalizeArgbColor does not resolve them.
- Remove inner whitespace from the value (outer whitespace is auto-trimmed, inner is not).
Example fix
// before fillColor="accent1" // after fillColor="FF0000" // or use a theme-color-aware property for accent1
Defensive patterns
Strategy: validation
Validate before calling
// Cheap pre-check: normalize then confirm 8 hex digits came back, or it is a known literal form.
static bool IsAcceptableArgbColor(string value)
{
try { return System.Text.RegularExpressions.Regex.IsMatch(
OfficeCli.Core.ParseHelpers.NormalizeArgbColor(value), @"^[0-9A-F]{8}$"); }
catch { return false; }
} Try / catch
try { var argb = ParseHelpers.NormalizeArgbColor(value); }
catch (ArgumentException ex) { /* report invalid color to user, keep prior value */ } Prevention
- Use supported literal forms (hex, named, rgb(), transparent).
- Route scheme/theme colors to theme-color-aware properties, not NormalizeArgbColor.
- Avoid inner whitespace in color values.
When it happens
Trigger: Calling a property that routes through NormalizeArgbColor (Excel cell/rich-text-run/conditional-format/sparkline colors, ExcelStyleManager hex) with a value that is none of the accepted forms — e.g. 'accent1' (a scheme color, not handled here), a 5-digit hex, '#FF 0000' (inner space), 'rgb(300,0,0)' out of range, or a misspelled color name.
Common situations: Trying to set a theme/scheme color (accent1, dark2, hyperlink) on a property that only accepts literal colors — these must go on theme-color-aware properties; copying a CSS color with inner whitespace; typos in named colors ('redd'); truncated hex.
Related errors
- Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
- Invalid '{propertyName}' value '{value}': degrees must be in
- Invalid '{propertyName}' value '{value}'. Expected a non-neg
- Invalid source range: {sourceRef}
- Column {startCol} out of range (max: XFD)
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/34ce5372ef393dbb.
Report an issue: GitHub.