{"record":{"id":"2567543c5444f627","repo":"dotnet/wpf","slug":"invaliddrawingattributeswidth","errorCode":null,"errorMessage":"InvalidDrawingAttributesWidth","messagePattern":"InvalidDrawingAttributesWidth","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":868,"sourceCode":"                if ( value.GetType() != typeof(double) )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(double)), nameof(value));\n                }\n\n                double dVal = (double)value;\n\n                if (id == KnownIds.StylusHeight)\n                {\n                    if ( Double.IsNaN(dVal) || dVal < DrawingAttributes.MinHeight || dVal > DrawingAttributes.MaxHeight)\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesHeight);\n                    }\n                }\n                else\n                {\n                    if (Double.IsNaN(dVal) ||  dVal < DrawingAttributes.MinWidth || dVal > DrawingAttributes.MaxWidth)\n                    {\n                        throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesWidth);\n                    }\n                }\n            }\n            else if ( id == KnownIds.Transparency )\n            {\n                if ( value.GetType() != typeof(byte) )\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte)), nameof(value));\n                }\n\n                double dVal = (double)value;\n            }\n            else\n            {\n                if ( !UsesEmbeddedTypeInformation(id) )\n                {\n                    // if this guid used the legacy internal attribute persistence APIs,\n                    //      then it doesn't include embedded type information (it's always a byte array)","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L850-L886","documentation":"ExtendedPropertySerializer rejects a value assigned to a DrawingAttributes extended property (Width/Height guid) whose double value is NaN, negative-below MinWidth, or above DrawingAttributes.MaxWidth. The library enforces the documented DrawingAttributes width range before persisting to ISF. It is an ArgumentOutOfRangeException naming the offending parameter.","triggerScenarios":"Calling ExtendedPropertySerializer.SaveAsBaseValue or DrawingAttributes extended-property serialization with value = double.NaN, a negative width, or a value > DrawingAttributes.MaxWidth for the Width (or Height-family) guid.","commonSituations":"Computing a stroke width from user input or math that yields NaN (e.g. 0/0) or negative values; deserializing config or older files with unvalidated widths; unit tests probing boundary values.","solutions":["Validate the double before assigning: check !double.IsNaN && >= DrawingAttributes.MinWidth && <= DrawingAttributes.MaxWidth","Clamp the value: Math.Max(DrawingAttributes.MinWidth, Math.Min(DrawingAttributes.MaxWidth, value))","Replace NaN with a sane default such as DrawingAttributes.DefaultWidth","Guard upstream data sources (config, files, network) that feed widths"],"exampleFix":"// before\nattr.AddPropertyData(CustomAttributeSerializer.CurrentWidthGuid, computedWidth); // may be NaN/negative\n// after\nif (!double.IsNaN(computedWidth) && computedWidth >= DrawingAttributes.MinWidth && computedWidth <= DrawingAttributes.MaxWidth)\n    attr.AddPropertyData(CustomAttributeSerializer.CurrentWidthGuid, computedWidth);\nelse\n    attr.Width = DrawingAttributes.DefaultWidth;","handlingStrategy":"validation","validationCode":"static bool IsValidWidth(double w) => !double.IsNaN(w) && !double.IsInfinity(w) && w >= System.Windows.Ink.DrawingAttributes.MinWidth && w <= System.Windows.Ink.DrawingAttributes.MaxWidth;","typeGuard":"static bool IsFiniteInRange(double v, double min, double max) => double.IsFinite(v) && v >= min && v <= max;","tryCatchPattern":"try { attr.AddPropertyData(widthGuid, value); }\ncatch (ArgumentOutOfRangeException) { attr.Width = System.Windows.Ink.DrawingAttributes.DefaultWidth; }","preventionTips":["Always clamp user/computed widths into [MinWidth, MaxWidth]","Reject or replace NaN/Infinity before assigning extended properties","Centralize width assignment in one validated setter","Add boundary unit tests for width serialization"],"tags":["wpf","ink","isf","argument-out-of-range","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}