iOfficeAI/OfficeCLI · error · ArgumentException

Invalid referenceLine value '{parts[0]}'. Expected: number o

Error message

Invalid referenceLine value '{parts[0]}'. Expected: number or number:color:label:dash (e.g. '50:FF0000:Target:dash') or number:color:width:dash (e.g. '50:FF0000:2:dash').

What it means

A reference line spec is parsed positionally from a colon-delimited string (value:color:label:dash or value:color:width:dash). The first segment (parts[0]) must be a numeric value parseable as a double with InvariantCulture. If double.TryParse fails on the trimmed first segment, the library rejects the entire spec with the expected format examples.

Source

Thrown at src/officecli/Core/Chart/ChartHelper.Advanced.cs:45

    /// e.g. "50", "75:FF0000", "100:00AA00:Target", "80:0000FF:Average:dash",
    ///      "50:FF0000:2.5:dash", "50:FF0000:2:dash:Target", "50:FF0000::dash:Target"
    /// </summary>
    internal static void AddReferenceLine(C.Chart chart, string spec, bool removeExisting = true)
    {
        const double DefaultWidthPt = 1.5;
        var plotArea = chart.GetFirstChild<C.PlotArea>();
        if (plotArea == null) return;

        // Caller may suppress the sweep when accumulating multiple lines from
        // a semicolon-joined value (see Setter `case "referenceline"`).
        if (removeExisting)
            RemoveExistingReferenceLines(plotArea);

        var parts = spec.Split(':');
        if (!double.TryParse(parts[0].Trim(),
            System.Globalization.NumberStyles.Float,
            System.Globalization.CultureInfo.InvariantCulture, out var refValue))
            throw new ArgumentException(
                $"Invalid referenceLine value '{parts[0]}'. Expected: number or number:color:label:dash (e.g. '50:FF0000:Target:dash') or number:color:width:dash (e.g. '50:FF0000:2:dash').");

        var color = parts.Length > 1 ? parts[1].Trim() : "FF0000";
        double widthPt = DefaultWidthPt;
        string label = $"Ref ({refValue.ToString("G", System.Globalization.CultureInfo.InvariantCulture)})";
        string dash = "dash";

        // Positional parse — see doc comment above. parts[0..1] already consumed.
        if (parts.Length == 3)
        {
            label = parts[2].Trim();
        }
        else if (parts.Length == 4)
        {
            var p2 = parts[2].Trim();
            var p3 = parts[3].Trim();
            // Disambiguate: "50:FF0000:2.5:dash" (width form) vs "50:FF0000:Target:dash" (legacy label form).
            // Only treat p2 as width if it parses as a number AND p3 is a recognized dash keyword — both

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Ensure the first segment is a plain number in invariant (dot-decimal) format: '50:FF0000:Target:dash'.
  2. Use a dot as the decimal separator: '0.5' not '0,5'.
  3. Check that no leading colon or label appears before the numeric value.

Example fix

// before
referenceline: "Target:FF0000:Label:dash"
// after
referenceline: "50:FF0000:Target:dash"
// 50 is the value, FF0000 is the color
Defensive patterns

Strategy: validation

Validate before calling

static bool TryParseReferenceLineValue(string spec, out double value)
{
    var parts = spec.Split(':');
    return double.TryParse(parts[0].Trim(), System.Globalization.NumberStyles.Float,
        System.Globalization.CultureInfo.InvariantCulture, out value);
}

Try / catch

try { ChartHelperAdvanced.AddReferenceLine(chart, spec); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid referenceLine value"))
{
    Console.Error.WriteLine($"{ex.Message}\nExpected format: number:color:label:dash");
}

Prevention

When it happens

Trigger: Passing a referenceLine value where the first colon-delimited segment is non-numeric: 'abc:red:Label:dash', ':FF0000', or 'N/A'. Called from the Setter case 'referenceline' or directly from the chart helper that splits the spec by ':'.

Common situations: Using locale-specific number formats with commas as decimal separators ('50,5:FF0000'). Passing a label as the first segment by mistake. Using an empty value. Using a formula reference instead of a literal number.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/6ab841c0787f4019. Report an issue: GitHub.