dotnet/wpf · error · ArgumentOutOfRangeException
SR.Format(SR.InvalidCtorParameterNoNegative, "value")
Error message
SR.Format(SR.InvalidCtorParameterNoNegative, "value")
What it means
The FigureLength constructor rejects a negative value (value < 0.0) with ArgumentOutOfRangeException. Figure lengths are non-negative quantities; Auto/Pixel/Column/Content/Page all require value >= 0.
Solutions
- Clamp with Math.Max(0, value) before constructing the FigureLength.
- Validate the input value before the call and reject or correct negatives at the source.
- Fix the upstream calculation that produces a negative size.
Example fix
// before var length = new FigureLength(available - used, FigureUnitType.Pixel); // may be negative // after var length = new FigureLength(Math.Max(0, available - used), FigureUnitType.Pixel);
Defensive patterns
Strategy: validation
Validate before calling
if (value < 0.0)
throw new ArgumentOutOfRangeException(nameof(value), "FigureLength value must be non-negative."); Type guard
bool IsNonNegative(double v) => !double.IsNaN(v) && v >= 0.0;
Try / catch
try { var len = new FigureLength(value, unit); }
catch (ArgumentOutOfRangeException) { /* clamp to 0 or recompute the size */ } Prevention
- Clamp computed sizes with Math.Max(0, x) before constructing lengths.
- Validate user/parsed input for negativity at ingestion.
- Review subtraction-based layout math for sign errors.
When it happens
Trigger: Calling new FigureLength(x, type) with x < 0.0 for any FigureUnitType — e.g. subtracting margins into a computed size.
Common situations: Computed sizes going negative after subtraction; parsing user input without validation; sign errors in layout math.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4d5d5997a6dc64ed.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs:111
/// 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);
}
if (type == FigureUnitType.Column)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, maxColumns);
}View on GitHub (pinned to 81131a70a4)