{"record":{"id":"91a8b91cadb6355f","repo":"dotnet/wpf","slug":"sr-invaliddrawingattributeswidth","errorCode":null,"errorMessage":"SR.InvalidDrawingAttributesWidth","messagePattern":"SR\\.InvalidDrawingAttributesWidth","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs","lineNumber":188,"sourceCode":"        /// The width of the StylusTip\n        /// </summary>\n        public double Width\n        {\n            get\n            {\n                //prevent boxing / unboxing if possible\n                if (!_extendedProperties.Contains(KnownIds.StylusWidth))\n                {\n                    Debug.Assert(DrawingAttributes.DefaultWidth == (double)GetDefaultDrawingAttributeValue(KnownIds.StylusWidth));\n                    return DrawingAttributes.DefaultWidth;\n                }\n                return (double)GetExtendedPropertyBackedProperty(KnownIds.StylusWidth);\n            }\n            set\n            {\n                if (double.IsNaN(value) || value < MinWidth || value > MaxWidth)\n                {\n                    throw new ArgumentOutOfRangeException(\"Width\", SR.InvalidDrawingAttributesWidth);\n                }\n                //no need to raise change events, they will bubble up from the EPC\n                //underneath us\n                SetExtendedPropertyBackedProperty(KnownIds.StylusWidth, value);\n            }\n        }\n\n        /// <summary>\n        /// When true, ink will be rendered as a series of curves instead of as\n        /// lines between Stylus sample points. This is useful for smoothing the ink, especially\n        /// when the person writing the ink has jerky or shaky writing.\n        /// This value is TRUE by default in the Avalon implementation\n        /// </summary>\n        public bool FitToCurve\n        {\n            get\n            {\n                DrawingFlags flags = (DrawingFlags)GetExtendedPropertyBackedProperty(KnownIds.DrawingFlags);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs#L170-L206","documentation":"DrawingAttributes.Width setter throws ArgumentOutOfRangeException with SR.InvalidDrawingAttributesWidth when the value is NaN, below MinWidth, or above MaxWidth. Width sizes the stylus tip across its minor axis and must be a finite in-range double. Valid bounds are the public DrawingAttributes.MinWidth/MaxWidth constants.","triggerScenarios":"Assigning double.NaN, a negative or too-small value, or a value exceeding MaxWidth to DrawingAttributes.Width — typically from user input or dynamic computation.","commonSituations":"Two-way data binding to an editable field without validation; NaN from failed parsing; unit conversion mistakes (px vs mm) producing extreme values.","solutions":["Clamp with Math.Clamp(value, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth).","Reject or default NaN values before assignment using double.IsNaN.","Set the input control's Min/Max limits to match MinWidth/MaxWidth."],"exampleFix":"// before\nda.Width = double.Parse(text); // may be NaN/out of range\n// after\nif (double.TryParse(text, out var w) && !double.IsNaN(w))\n    da.Width = Math.Clamp(w, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth);","handlingStrategy":"validation","validationCode":"static bool IsValidWidth(double v) => !double.IsNaN(v) && v >= DrawingAttributes.MinWidth && v <= DrawingAttributes.MaxWidth;","typeGuard":"static bool IsFiniteInRange(double v, double min, double max) => !double.IsNaN(v) && !double.IsInfinity(v) && v >= min && v <= max;","tryCatchPattern":"try { da.Width = value; }\ncatch (ArgumentOutOfRangeException) { da.Width = DrawingAttributes.DefaultWidth; }","preventionTips":["Clamp with Math.Clamp(value, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth)","Validate parsed input with double.TryParse plus range check","Mirror MinWidth/MaxWidth into UI validation rules"],"tags":["wpf","ink","argumentoutofrange","validation"],"backgroundTag":"argument-out-of-range","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"}