{"record":{"id":"d8f951022cf73622","repo":"dotnet/wpf","slug":"sr-format-sr-invalidctorparameternonan-value","errorCode":null,"errorMessage":"SR.Format(SR.InvalidCtorParameterNoNaN, \"value\")","messagePattern":"SR\\.Format\\(SR\\.InvalidCtorParameterNoNaN, \"value\"\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs","lineNumber":103,"sourceCode":"        /// instance.</param>\n        /// <remarks> \n        /// If the <c>type</c> parameter is <c>FigureUnitType.Auto</c>, \n        /// then passed in value is ignored and replaced with <c>0</c>.\n        /// </remarks>\n        /// <exception cref=\"ArgumentException\">\n        /// If <c>value</c> parameter is <c>double.NaN</c>\n        /// or <c>value</c> parameter is <c>double.NegativeInfinity</c>\n        /// or <c>value</c> parameter is <c>double.PositiveInfinity</c>.\n        /// or <c>value</c> parameter is <c>negative</c>.\n        /// </exception>\n        public FigureLength(double value, FigureUnitType type)\n        {\n            double maxColumns = PTS.Restrictions.tscColumnRestriction;\n            double maxPixel = Math.Min(1000000, PTS.MaxPageSize);\n\n            if (double.IsNaN(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoNaN, \"value\"));\n            }\n            if (double.IsInfinity(value))\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterNoInfinity, \"value\"));\n            }\n            if (value < 0.0)\n            {\n                throw new ArgumentOutOfRangeException(SR.Format(SR.InvalidCtorParameterNoNegative, \"value\"));\n            }\n            if (    type != FigureUnitType.Auto\n                &&  type != FigureUnitType.Pixel\n                &&  type != FigureUnitType.Column\n                &&  type != FigureUnitType.Content\n                &&  type != FigureUnitType.Page   )\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidCtorParameterUnknownFigureUnitType, \"type\"));\n            }\n            if (type is FigureUnitType.Content or FigureUnitType.Page)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FigureLength.cs#L85-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar length = new FigureLength(computedValue, FigureUnitType.Pixel); // NaN throws\n\n// after\nvar length = double.IsNaN(computedValue)\n    ? FigureLength.Auto\n    : new FigureLength(computedValue, FigureUnitType.Pixel);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(value))\n    throw new ArgumentException(\"value must not be NaN.\");\nvar length = new FigureLength(value, unit);","typeGuard":"bool IsValidFigureLength(double v) => !double.IsNaN(v) && !double.IsInfinity(v) && v >= 0;","tryCatchPattern":"try { var len = new FigureLength(value, unit); }\ncatch (ArgumentException) { /* fall back to FigureLength.Auto */ }","preventionTips":["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)."],"tags":["wpf","invalid-argument-value","nan","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}