iOfficeAI/OfficeCLI · error · ArgumentException
Invalid '{propertyName}' value '{value}'. Expected a finite
Error message
Invalid '{propertyName}' value '{value}'. Expected a finite number. What it means
Thrown by ParseHelpers.SafeParseDouble when the value is not a finite number. Parsing uses NumberStyles.Float (NOT the default Float|AllowThousands), so it deliberately rejects thousands separators — this prevents a comma-decimal-locale input like '45,5' silently becoming 455. NaN and +/-Infinity are also rejected even if they parse.
Source
Thrown at src/officecli/Core/ParseHelpers.cs:489
// inherently position-ordered, and lets a future text-mutating path process
// ranges back-to-front (descending) so earlier offsets stay valid — the same
// reason ProcessFindInParagraph iterates its matches in reverse.
result.Sort((a, b) => a.Start != b.Start ? a.Start.CompareTo(b.Start) : a.End.CompareTo(b.End));
return result;
}
/// <summary>
/// Safely parse a string as double, throwing ArgumentException with a clear message on failure.
/// </summary>
public static double SafeParseDouble(string value, string propertyName)
{
// NumberStyles.Float (NOT the default Float|AllowThousands) — matches every
// other numeric parser in this file. AllowThousands would silently strip a
// decimal comma ("45,5" -> 455), producing a 10x/1000x-wrong value from a
// comma-decimal-locale input instead of rejecting it.
if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)
|| double.IsNaN(result) || double.IsInfinity(result))
throw new ArgumentException($"Invalid '{propertyName}' value '{value}'. Expected a finite number.");
return result;
}
/// <summary>
/// Parse a rotation value in degrees. Rejects non-finite, NaN, and values
/// outside [-3600, 3600] degrees (ten full revolutions either direction).
/// OOXML stores rotation as ST_Angle (60000ths of a degree) which fits in
/// an Int32 up to ~±35790°, but values above ~±3600° are functionally
/// indistinguishable from their modulo-360 reduction while opening the
/// door to silent overflow on the (deg * 60000) multiply. The clamp is
/// applied uniformly across pptx shape/group/connector add+set sites.
/// </summary>
public static double SafeParseRotationDegrees(string value, string propertyName)
{
var deg = SafeParseDouble(value, propertyName);
if (deg < -3600 || deg > 3600)
throw new ArgumentException($"Invalid '{propertyName}' value '{value}': degrees must be in [-3600, 3600].");
return deg;View on GitHub (pinned to 1ced45e900)
Solutions
- Use a plain invariant-culture number, e.g. '45.5' with a dot decimal and no thousands separators.
- Strip any unit suffix ('%', 'pt', 'cm', 'in') only if the specific caller documents it strips them — otherwise pass the bare number.
- For locale-comma decimals, convert to a dot decimal before submitting.
Example fix
// before charspacing="45,5" // after charspacing="45.5"
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate with the SAME NumberStyles.Float rule the parser uses:
static bool IsFiniteNumber(string value)
=> double.TryParse(value, System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out var d)
&& !double.IsNaN(d) && !double.IsInfinity(d); Prevention
- Always use a dot decimal and no thousands separators for numeric properties.
- Strip unit suffixes only where the caller documents it strips them.
- Convert locale-comma decimals to dot decimals before submission.
When it happens
Trigger: Any numeric property routed through SafeParseDouble: rotation (non-PPT), charspacing, crop, width, twips, trendline.forward/backward/intercept, axis min/max/unit, logBase, alpha, etc. Triggered by non-numeric text, a locale-comma decimal ('45,5'), thousands grouping ('1,000'), 'NaN', 'Infinity', or trailing units left on the value.
Common situations: Passing '45,5' in a comma-decimal locale (must be '45.5'); passing '100%' with the '%' still attached when the caller did not strip it; empty string for a numeric field; copy-pasting '1.024,5' (EU format) from a spreadsheet.
Related errors
- Invalid '{propertyName}' value '{value}'. Expected a non-neg
- Invalid '{propertyName}' value '{value}'. Expected an intege
- Invalid range '{spec}': end ({end}) must be >= start ({start
- Invalid range '{spec}'. Expected one or more 'start:end' ran
- Invalid '{propertyName}' value '{value}': degrees must be in
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/aabf1567bd652e3c.
Report an issue: GitHub.