iOfficeAI/OfficeCLI · error · ArgumentException
Invalid '{propertyName}' value '{value}'. Expected a non-neg
Error message
Invalid '{propertyName}' value '{value}'. Expected a non-negative integer. What it means
Thrown by ParseHelpers.SafeParseUint when the value is not a valid non-negative uint (culture-invariant parse). Rejects negatives, non-integers, decimals, locale grouping, and any non-numeric text. Used for properties that must be whole non-negative counts: Excel rotation/indent/zoom/paperSize/padding/width and calc.iterateCount.
Source
Thrown at src/officecli/Core/ParseHelpers.cs:532
/// (e.g. 99999° wraps to a garbage 1.7e9 angle that real Excel refuses
/// with 0x800A03EC). Reducing modulo 360 first keeps the value in the
/// spec range [0, 21600000) — geometrically identical, overflow-proof,
/// and always producing a file Excel accepts. Shared by the shape and
/// chart gradient builders so their angle handling stays consistent.
/// </summary>
public static int GradientAngleToOoxmlUnits(int degrees)
{
var normalized = ((degrees % 360) + 360) % 360;
return normalized * 60000;
}
/// <summary>
/// Safely parse a string as uint, throwing ArgumentException with a clear message on failure.
/// </summary>
public static uint SafeParseUint(string value, string propertyName)
{
if (!uint.TryParse(value, CultureInfo.InvariantCulture, out var result))
throw new ArgumentException($"Invalid '{propertyName}' value '{value}'. Expected a non-negative integer.");
return result;
}
/// <summary>
/// Safely parse a string as byte, throwing ArgumentException with a clear message on failure.
/// </summary>
public static byte SafeParseByte(string value, string propertyName)
{
if (!byte.TryParse(value, CultureInfo.InvariantCulture, out var result))
throw new ArgumentException($"Invalid '{propertyName}' value '{value}'. Expected an integer (0-255).");
return result;
}
/// <summary>
/// Normalize a hex color string to 8-char ARGB format (e.g. "FFFF0000").
/// Accepts: "FF0000" (6-char RGB → prepend FF), "#FF0000" (strip #), "F00" (3-char → expand),
/// "80FF0000" (8-char ARGB → as-is). Always returns uppercase.
/// </summary>View on GitHub (pinned to 1ced45e900)
Solutions
- Supply a whole, non-negative integer with no units, e.g. zoom="120".
- Strip '%' or other suffixes before the value reaches the parser (zoom paths expect a plain int).
- For Excel text rotation use 0-180; negative or >180 are invalid here (this is the Excel uint rotation, distinct from PPT degrees).
Example fix
// before zoom="120%" // after zoom="120"
Defensive patterns
Strategy: validation
Validate before calling
static bool IsNonNegativeInt(string value)
=> uint.TryParse(value, System.Globalization.CultureInfo.InvariantCulture, out _); Prevention
- Pass whole non-negative integers with no units for uint fields.
- Strip '%' and other suffixes before the value reaches the parser.
- Handle special tokens like 'auto' on width/padding BEFORE calling SafeParseUint.
When it happens
Trigger: Passing a negative number, a decimal ('1.5'), a percent/unit suffix, or text to any uint property: rotation, indent, zoom, paperSize, padding, width, calc.iterateCount.
Common situations: Passing 'auto' to a width/padding field whose caller did not pre-handle it (some width paths special-case 'auto' before calling SafeParseUint); passing '-10' for indent/rotation; passing '120%' for zoom with '%' still attached; passing a decimal font/size value where a uint is required.
Related errors
- Invalid '{propertyName}' value '{value}'. Expected a finite
- Invalid '{propertyName}' value '{value}'. Expected an intege
- Invalid color value: '{value}'. Expected 6-digit hex RGB (e.
- Invalid range '{spec}': end ({end}) must be >= start ({start
- Invalid range '{spec}'. Expected one or more 'start:end' ran
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/bbe46c790c65c75b.
Report an issue: GitHub.