{"record":{"id":"e9e034f2a91c7675","repo":"dotnet/wpf","slug":"microsoft-windows-controls-sr-format-microsoft-windows-e9e034","errorCode":null,"errorMessage":"Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Controls.SR.InvalidCtorParameterNoNaN, \"value\")","messagePattern":"Microsoft\\.Windows\\.Controls\\.SR\\.Format\\(Microsoft\\.Windows\\.Controls\\.SR\\.InvalidCtorParameterNoNaN, \"value\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs","lineNumber":50,"sourceCode":"        #region Constructors\n\n        /// <summary>\n        ///   Constructor, initializes the RibbonControlLength as absolute value in pixels.\n        /// </summary>\n        public RibbonControlLength(double pixels)\n            : this(pixels, RibbonControlLengthUnitType.Pixel)\n        {\n        }\n\n        /// <summary>\n        ///   Constructor, initializes the RibbonControlLength and specifies what kind of value \n        ///   it will hold.\n        /// </summary>\n        public RibbonControlLength(double value, RibbonControlLengthUnitType type)\n        {\n            if (double.IsNaN(value))\n            {\n                throw new ArgumentException(Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Controls.SR.InvalidCtorParameterNoNaN, \"value\"));\n            }\n\n            if (type == RibbonControlLengthUnitType.Star && double.IsInfinity(value))\n            {\n                throw new ArgumentException(Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Controls.SR.InvalidCtorParameterNoInfinityForStarSize, \"value\"));\n            }\n\n            if (type != RibbonControlLengthUnitType.Auto\n                && type != RibbonControlLengthUnitType.Pixel\n                && type != RibbonControlLengthUnitType.Item\n                && type != RibbonControlLengthUnitType.Star)\n            {\n                throw new ArgumentException(Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Controls.SR.InvalidCtorParameterUnknownRibbonControlLengthUnitType, \"type\"));\n            }\n\n            _unitValue = (type == RibbonControlLengthUnitType.Auto) ? 0.0 : value;\n            _unitType = type;\n        }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs#L32-L68","documentation":"The RibbonControlLength(double, RibbonControlLengthUnitType) constructor rejects NaN values because a length cannot be 'not a number'; it throws ArgumentException with a message saying the 'value' parameter must not be NaN. (Star units additionally reject infinity, but the NaN check applies to all unit types.)","triggerScenarios":"Calling new RibbonControlLength(double.NaN, ...) with any unit type - typically when a computed width/height (e.g. from ActualWidth during layout, or an unbound/databound double that defaulted to NaN) is passed to the constructor.","commonSituations":"Passing a control's ActualWidth before layout completes (NaN), databinding a length property where the source is NaN, or math that produced NaN (0/0, infinity-infinity) before constructing the length.","solutions":["Guard the input with double.IsNaN(value) before constructing and substitute a sane default (e.g. Auto or a fixed pixel length).","Delay construction until layout has produced real measurements instead of using ActualWidth during measure/arrange pass.","Fix the upstream calculation producing NaN (check for division by zero or uninitialized doubles).","If the API surface allows, use RibbonControlLength.Auto instead of a NaN-sized value."],"exampleFix":"// before\nvar length = new RibbonControlLength(element.ActualWidth, RibbonControlLengthUnitType.Pixel); // NaN before layout\n\n// after\nvar length = double.IsNaN(element.ActualWidth)\n    ? RibbonControlLength.Auto\n    : new RibbonControlLength(element.ActualWidth, RibbonControlLengthUnitType.Pixel);","handlingStrategy":"validation","validationCode":"if (double.IsNaN(raw))\n    throw new ArgumentException(\"Length value must not be NaN before constructing RibbonControlLength\");\nvar length = new RibbonControlLength(raw, RibbonControlLengthUnitType.Pixel);","typeGuard":"bool IsUsableLength(double v) => !double.IsNaN(v) && !(type == RibbonControlLengthUnitType.Star && double.IsInfinity(v)); // pair with the unit type in scope","tryCatchPattern":"try { var length = new RibbonControlLength(value, type); }\ncatch (ArgumentException) { var length = RibbonControlLength.Auto; /* NaN from unfinished layout */ }","preventionTips":["Never pass ActualWidth/ActualHeight during the measure pass; they can be NaN.","Validate doubles for NaN (and Infinity for Star units) before constructing lengths.","Prefer RibbonControlLength.Auto over a computed NaN value.","Fix upstream math that can yield NaN (division by zero, inf-inf)."],"tags":["wpf","ribbon","argumentexception","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"}