dotnet/wpf · error · ArgumentOutOfRangeException
InvalidDrawingAttributesHeight
Error message
InvalidDrawingAttributesHeight
What it means
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.
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
Example fix
// before
drawingAttributes.Height = userHeight; // may be NaN or out of range
// after
if (!double.IsNaN(userHeight))
drawingAttributes.Height = Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, userHeight)); Defensive patterns
Strategy: validation
Validate before calling
static double ClampHeight(double h) => double.IsNaN(h) ? DrawingAttributes.DefaultHeight : Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, h));
Type guard
static bool IsValidHeight(double h) => !double.IsNaN(h) && h >= DrawingAttributes.MinHeight && h <= DrawingAttributes.MaxHeight;
Try / catch
try { serializer.Serialize(...); }
catch (ArgumentOutOfRangeException) { drawingAttributes.Height = DrawingAttributes.DefaultHeight; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- SR.InvalidDrawingAttributesHeight
- SR.InvalidDrawingAttributesWidth
- Argument out of range (end not contained in view)
- Argument out of range (position does not map to a line)
- Argument out of range (start not contained in view)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ed1d3b2ccc05d9e5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs:861
if ( value.GetType() != typeof(bool))
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(bool)), nameof(value));
}
}
else if ( id == KnownIds.StylusHeight || id == KnownIds.StylusWidth )
{
if ( value.GetType() != typeof(double) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(double)), nameof(value));
}
double dVal = (double)value;
if (id == KnownIds.StylusHeight)
{
if ( Double.IsNaN(dVal) || dVal < DrawingAttributes.MinHeight || dVal > DrawingAttributes.MaxHeight)
{
throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesHeight);
}
}
else
{
if (Double.IsNaN(dVal) || dVal < DrawingAttributes.MinWidth || dVal > DrawingAttributes.MaxWidth)
{
throw new ArgumentOutOfRangeException(nameof(value), SR.InvalidDrawingAttributesWidth);
}
}
}
else if ( id == KnownIds.Transparency )
{
if ( value.GetType() != typeof(byte) )
{
throw new ArgumentException(SR.Format(SR.InvalidValueType, typeof(byte)), nameof(value));
}
double dVal = (double)value;View on GitHub (pinned to 81131a70a4)