{"record":{"id":"ed1d3b2ccc05d9e5","repo":"dotnet/wpf","slug":"invaliddrawingattributesheight","errorCode":null,"errorMessage":"InvalidDrawingAttributesHeight","messagePattern":"InvalidDrawingAttributesHeight","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs","lineNumber":861,"sourceCode":"                if ( value.GetType() != typeof(bool))\n                {\n                    throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(bool)), nameof(value));\n                }\n            }\n            else if ( id == KnownIds.StylusHeight || id == KnownIds.StylusWidth )\n            {\n                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;","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs#L843-L879","documentation":"For StylusHeight (and analogously StylusWidth via InvalidDrawingAttributesWidth), ExtendedPropertySerializer enforces DrawingAttributes bounds: the double value must not be NaN and must lie within DrawingAttributes.MinHeight..MaxHeight. Violations throw ArgumentOutOfRangeException with SR.InvalidDrawingAttributesHeight.","triggerScenarios":"Setting StylusHeight to NaN, a negative number, or a value above DrawingAttributes.MaxHeight (e.g. user-supplied UI input, computed heights from a stroke's bounds) and serializing/validating.","commonSituations":"Dividing by zero stroke metrics producing NaN; unclamped user input in a pen-width slider; computing height from tiny/empty strokes; unit conversion mistakes (pixels vs HIMETRIC) yielding huge values.","solutions":["Clamp the value with Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, value)) before assigning","Reject or replace NaN with a default (e.g. DrawingAttributes.DefaultHeight)","Catch ArgumentOutOfRangeException and normalize the height"],"exampleFix":"// before\ndrawingAttributes.Height = userHeight; // may be NaN or out of range\n// after\nif (!double.IsNaN(userHeight))\n    drawingAttributes.Height = Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, userHeight));","handlingStrategy":"validation","validationCode":"static double ClampHeight(double h) => double.IsNaN(h) ? DrawingAttributes.DefaultHeight : Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, h));","typeGuard":"static bool IsValidHeight(double h) => !double.IsNaN(h) && h >= DrawingAttributes.MinHeight && h <= DrawingAttributes.MaxHeight;","tryCatchPattern":"try { serializer.Serialize(...); }\ncatch (ArgumentOutOfRangeException) { drawingAttributes.Height = DrawingAttributes.DefaultHeight; }","preventionTips":["Always clamp user/UI-driven pen sizes to Min/Max","Replace NaN from computations with a default before storing","Add range unit tests around DrawingAttributes Height/Width setters"],"tags":["wpf","ink","argumentoutofrange","drawingattributes"],"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"}