dotnet/wpf · error · ArgumentException

SR.Format(SR.InvalidCtorParameterNoInfinity, "value")

Error message

SR.Format(SR.InvalidCtorParameterNoInfinity, "value")

What it means

The FigureLength constructor rejects a value of double.PositiveInfinity or double.NegativeInfinity. Infinity is not a valid figure length; the constructor throws ArgumentException with InvalidCtorParameterNoInfinity.

Solutions

  1. Clamp or validate with double.IsInfinity before constructing the FigureLength.
  2. Use FigureUnitType.Page or Content to express 'fill' semantics instead of infinity.
  3. Fix upstream math that yields infinity (e.g. division by zero or max on empty collections).

Example fix

// before
var length = new FigureLength(double.PositiveInfinity, FigureUnitType.Pixel); // throws

// after
var length = double.IsInfinity(requested)
    ? new FigureLength(1.0, FigureUnitType.Page)
    : new FigureLength(requested, FigureUnitType.Pixel);
Defensive patterns

Strategy: validation

Validate before calling

if (double.IsInfinity(value))
    throw new ArgumentException("value must not be infinite.");
var length = new FigureLength(value, unit);

Type guard

bool IsFiniteLength(double v) => !double.IsNaN(v) && !double.IsInfinity(v);

Try / catch

try { var len = new FigureLength(value, unit); }
catch (ArgumentException) { /* clamp or fall back to Page/Content unit */ }

Prevention

When it happens

Trigger: Calling new FigureLength(double.PositiveInfinity, ...) or with NegativeInfinity — e.g. passing double.PositiveInfinity to mean 'fill available space'.

Common situations: Using double.PositiveInfinity as a 'stretch to max' convention in layout code; values computed from unbounded measurements; interop with code that uses infinity as a default.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/cfea135c0c6d066b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs:107

        /// </remarks>
        /// <exception cref="ArgumentException">
        /// If <c>value</c> parameter is <c>double.NaN</c>
        /// or <c>value</c> parameter is <c>double.NegativeInfinity</c>
        /// or <c>value</c> parameter is <c>double.PositiveInfinity</c>.
        /// or <c>value</c> parameter is <c>negative</c>.
        /// </exception>
        public FigureLength(double value, FigureUnitType type)
        {
            double maxColumns = PTS.Restrictions.tscColumnRestriction;
            double maxPixel = Math.Min(1000000, PTS.MaxPageSize);

            if (double.IsNaN(value))
            {
                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, "value"));
            }
            if (double.IsInfinity(value))
            {
                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoInfinity, "value"));
            }
            if (value < 0.0)
            {
                throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidCtorParameterNoNegative, "value"));
            }
            if (    type != FigureUnitType.Auto
                &&  type != FigureUnitType.Pixel
                &&  type != FigureUnitType.Column
                &&  type != FigureUnitType.Content
                &&  type != FigureUnitType.Page   )
            {
                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, "type"));
            }
            if (type is FigureUnitType.Content or FigureUnitType.Page)
            {
                ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 1.0);
            }

View on GitHub (pinned to 81131a70a4)