iOfficeAI/OfficeCLI · warning · ArgumentException

Invalid 'softedge' value '{value}'. Expected a finite non-ne

Error message

Invalid 'softedge' value '{value}'. Expected a finite non-negative numeric radius in points.

What it means

BuildSoftEdge expects a softedge radius in points. It strips an optional trailing 'pt' (case-insensitive) and double-parses the remainder under the invariant culture, then rejects NaN, infinity, or negatives. The result is converted to EMU (radiusPt * EmuConverter.EmuPerPoint, 12700 EMU/pt).

Source

Thrown at src/officecli/Core/DrawingEffectsHelper.cs:170

            EndAlpha = 300,
            EndPosition = endPos,
            Distance = 0,
            Direction = 5400000,
            VerticalRatio = -100000,
            Alignment = Drawing.RectangleAlignmentValues.BottomLeft,
            RotateWithShape = false
        };
    }

    /// <summary>
    /// Build a SoftEdge element from a value string (radius in points).
    /// </summary>
    public static Drawing.SoftEdge BuildSoftEdge(string value)
    {
        var numStr = value.EndsWith("pt", StringComparison.OrdinalIgnoreCase) ? value[..^2].Trim() : value;
        if (!double.TryParse(numStr, System.Globalization.CultureInfo.InvariantCulture, out var radiusPt)
            || double.IsNaN(radiusPt) || double.IsInfinity(radiusPt) || radiusPt < 0)
            throw new ArgumentException($"Invalid 'softedge' value '{value}'. Expected a finite non-negative numeric radius in points.");
        return new Drawing.SoftEdge { Radius = (long)(radiusPt * EmuConverter.EmuPerPoint) };
    }

    /// <summary>
    /// Get or create EffectList in correct schema position within Drawing.RunProperties.
    /// CT_TextCharacterProperties order: ln → fill → effectLst → highlight → ... → latin → ea → ...
    /// </summary>
    public static Drawing.EffectList EnsureRunEffectList(Drawing.RunProperties rPr)
    {
        var existing = rPr.GetFirstChild<Drawing.EffectList>();
        if (existing != null) return existing;

        var effectList = new Drawing.EffectList();
        var insertBefore = (OpenXmlElement?)rPr.GetFirstChild<Drawing.Highlight>()
            ?? (OpenXmlElement?)rPr.GetFirstChild<Drawing.UnderlineFollowsText>()
            ?? (OpenXmlElement?)rPr.GetFirstChild<Drawing.Underline>()
            ?? (OpenXmlElement?)rPr.GetFirstChild<Drawing.UnderlineFillText>()
            ?? (OpenXmlElement?)rPr.GetFirstChild<Drawing.UnderlineFill>()

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Supply a non-negative number in points, optionally with a 'pt' suffix: '8' or '8pt'.
  2. Avoid other units (px/cm/in) — only 'pt' is recognized, bare numbers are points.
  3. Use a '.' decimal separator.

Example fix

// before
shape.softedge="-5"
shape.softedge="5px"

// after
shape.softedge="5"
shape.softedge="5pt"
Defensive patterns

Strategy: validation

Validate before calling

static bool IsValidSoftEdge(string v)
{
    var n = v.EndsWith("pt", StringComparison.OrdinalIgnoreCase) ? v[..^2].Trim() : v;
    return double.TryParse(n, CultureInfo.InvariantCulture, out var r)
        && !double.IsNaN(r) && !double.IsInfinity(r) && r >= 0;
}

Try / catch

try { DrawingEffectsHelper.BuildSoftEdge(value); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Invalid 'softedge'", StringComparison.Ordinal))
{ errors.Add(ex.Message); }

Prevention

When it happens

Trigger: A softedge value like 'abc', '-5', '-5pt', '5px' (px isn't converted and parses but is misleading), 'NaN', 'infinity', or a locale decimal '5,5' parsed under invariant culture.

Common situations: User supplies a unit other than points ('5px', '5cm') that either fails to parse or parses misleadingly; a negative radius; a comma decimal separator on a machine where invariant culture rejects it.

Related errors


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