iOfficeAI/OfficeCLI · error · ArgumentException
Invalid referenceLine width '{widthStr}'. Expected a number
Error message
Invalid referenceLine width '{widthStr}'. Expected a number in points (e.g. '1.5'), or empty for default {DefaultWidthPt}pt. What it means
In the canonical 5-part referenceLine form (value:color:width:dash:label), parts[2] is the line width in points. If the width segment is non-empty and fails double.TryParse (InvariantCulture), the library rejects it. An empty width segment is valid and defaults to DefaultWidthPt. This only applies to the 5-part form; the 3-part form treats parts[2] as a label.
Source
Thrown at src/officecli/Core/Chart/ChartHelper.Advanced.cs:87
widthPt = w4;
dash = p3;
}
else
{
label = p2;
dash = p3;
}
}
else if (parts.Length >= 5)
{
// Canonical 5-part form: value:color:width:dash:label (extra parts after label are joined
// back with ':' so labels containing literal colons survive a round-trip).
var widthStr = parts[2].Trim();
if (widthStr.Length > 0)
{
if (!double.TryParse(widthStr, System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out widthPt))
throw new ArgumentException(
$"Invalid referenceLine width '{widthStr}'. Expected a number in points (e.g. '1.5'), or empty for default {DefaultWidthPt}pt.");
}
dash = parts[3].Trim();
label = string.Join(':', parts.Skip(4)).Trim();
}
if (widthPt <= 0 || widthPt > 100)
throw new ArgumentException(
$"Invalid referenceLine width '{widthPt.ToString("G", System.Globalization.CultureInfo.InvariantCulture)}'. Expected a positive number of points, typically 0.25–10.");
// Warn: percent-stacked value axis is 0-1 (displayed 0%-100%). A refValue > 1
// is almost always a mistake — user likely forgot to convert 50 → 0.5.
// Without this check, Excel silently stretches the val axis to fit (e.g. 5000%),
// producing a chart where the real bars are compressed to a thin sliver on the left.
if (refValue > 1.0 && IsPercentStackedChart(plotArea))
{
var refMsg =
$"referenceLine value {refValue.ToString("G", System.Globalization.CultureInfo.InvariantCulture)} "View on GitHub (pinned to 1ced45e900)
Solutions
- Ensure the width segment (parts[2] in the 5-part form) is a numeric value in points: '50:FF0000:1.5:dash:Label'.
- Leave the width segment empty to use the default: '50:FF0000::dash:Label'.
- If you intended a 3-part form with a label, remember that parts[2] in a 3-part spec is the label, not the width — add width only in the 5-part form.
Example fix
// before referenceline: "50:FF0000:thick:dash:Target" // after referenceline: "50:FF0000:1.5:dash:Target" // or empty width for default referenceline: "50:FF0000::dash:Target"
Defensive patterns
Strategy: validation
Validate before calling
static bool TryValidateRefLineWidth(string spec)
{
var parts = spec.Split(':');
if (parts.Length < 5) return true; // 5-part form only
var widthStr = parts[2].Trim();
if (widthStr.Length == 0) return true; // empty = default
return double.TryParse(widthStr, System.Globalization.NumberStyles.Float,
System.Globalization.CultureInfo.InvariantCulture, out _);
} Try / catch
try { ChartHelperAdvanced.AddReferenceLine(chart, spec); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid referenceLine width") && ex.Message.Contains("Expected a number"))
{
Console.Error.WriteLine($"Width segment is non-numeric. Use a number or leave empty for default.");
} Prevention
- Remember the 5-part form is value:color:width:dash:label — width is parts[2].
- Leave the width segment empty to use the default.
- Use dot-decimal format for the width value.
When it happens
Trigger: Passing a referenceLine spec with 5+ colon-separated segments where the third segment (width) is non-numeric: '50:FF0000:thick:dash:Label'. The spec must have >= 5 parts to enter this code path.
Common situations: Confusing the 3-part form (value:color:label) with the 5-part form (value:color:width:dash:label) and placing a non-numeric string in the width slot. Using locale-specific decimal separators in the width ('1,5' instead of '1.5').
Related errors
- Invalid referenceLine value '{parts[0]}'. Expected: number o
- Invalid referenceLine width '{widthPt.ToString("G", System.G
- Invalid legend position '{posSpec}'. Valid: none, top, botto
- Invalid threshold '{parts[0]}' in colorRule. Expected a numb
- Invalid threshold '{parts[i]}' in colorRule.
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/7c5bca3540980a0d.
Report an issue: GitHub.