dotnet/wpf · error · ArgumentException
SR.Format(SR.InvalidCtorParameterNoNaN, "value")
Error message
SR.Format(SR.InvalidCtorParameterNoNaN, "value")
What it means
The FigureLength(double, FigureUnitType) constructor rejects a value that is double.NaN. FigureLength describes a figure's width/height and NaN is not a representable length; the constructor throws ArgumentException with InvalidCtorParameterNoNaN.
Solutions
- Validate the value with double.IsNaN before constructing and substitute a valid value or FigureUnitType.Auto.
- Use FigureLength.Auto (or FigureUnitType.Auto) instead of NaN to express 'auto' sizing.
- Trace the source of the NaN (division by zero, uninitialized field, parse failure) and fix the upstream computation.
Example fix
// before
var length = new FigureLength(computedValue, FigureUnitType.Pixel); // NaN throws
// after
var length = double.IsNaN(computedValue)
? FigureLength.Auto
: new FigureLength(computedValue, FigureUnitType.Pixel); Defensive patterns
Strategy: validation
Validate before calling
if (double.IsNaN(value))
throw new ArgumentException("value must not be NaN.");
var length = new FigureLength(value, unit); Type guard
bool IsValidFigureLength(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && v >= 0;
Try / catch
try { var len = new FigureLength(value, unit); }
catch (ArgumentException) { /* fall back to FigureLength.Auto */ } Prevention
- Use FigureLength.Auto instead of NaN for auto sizing.
- Validate computed values before constructing lengths.
- Trace and eliminate NaN sources (0/0 division, uninitialized fields).
When it happens
Trigger: Calling new FigureLength(double.NaN, ...) — e.g. passing an unbound computed value or a default field never initialized to a real number — with any FigureUnitType.
Common situations: Propagating NaN from parsed input or division results; using double.NaN as a sentinel for 'auto' instead of FigureUnitType.Auto; databound or computed values not validated before constructing the length.
Related errors
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- SR.Format(SR.InvalidCtorParameterNoInfinity, "value")
- SR.Format(SR.InvalidCtorParameterNoNaN…
- SR.InvalidCtorParameterNoNaN
- ArgumentNullException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d8f951022cf73622.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs:103
/// instance.</param>
/// <remarks>
/// If the <c>type</c> parameter is <c>FigureUnitType.Auto</c>,
/// then passed in value is ignored and replaced with <c>0</c>.
/// </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)View on GitHub (pinned to 81131a70a4)