dotnet/wpf · error · ArgumentOutOfRangeException
SR.InvalidDrawingAttributesHeight
Error message
SR.InvalidDrawingAttributesHeight
What it means
DrawingAttributes.Height setter throws ArgumentOutOfRangeException with SR.InvalidDrawingAttributesHeight when the value is NaN, below MinHeight, or above MaxHeight. Stylus height must be a finite, in-range double because it directly sizes the ink stroke geometry. The valid bounds are exposed as DrawingAttributes.MinHeight/MaxHeight constants.
Solutions
- Clamp the value: Math.Max(DrawingAttributes.MinHeight, Math.Min(DrawingAttributes.MaxHeight, value)).
- Validate with double.IsNaN before assigning and substitute a sensible default (e.g. 1.0).
- Constrain the UI input control's Min/Max to DrawingAttributes.MinHeight/MaxHeight.
Example fix
// before da.Height = parsedValue; // may be NaN or out of range // after da.Height = Math.Clamp(parsedValue, DrawingAttributes.MinHeight, DrawingAttributes.MaxHeight);
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidHeight(double v) => !double.IsNaN(v) && v >= DrawingAttributes.MinHeight && v <= DrawingAttributes.MaxHeight;
Type guard
static bool IsFiniteInRange(double v, double min, double max) => !double.IsNaN(v) && !double.IsInfinity(v) && v >= min && v <= max;
Try / catch
try { da.Height = value; }
catch (ArgumentOutOfRangeException) { da.Height = DrawingAttributes.DefaultHeight; /* or clamp */ } Prevention
- Clamp with Math.Clamp(value, DrawingAttributes.MinHeight, DrawingAttributes.MaxHeight)
- Check double.IsNaN on any computed or parsed value before assignment
- Bound UI inputs (sliders/text boxes) to MinHeight/MaxHeight
When it happens
Trigger: Assigning double.NaN, a negative number, zero (if below MinHeight), or a value above MaxHeight to DrawingAttributes.Height — often from unparsed user input or computed geometry.
Common situations: Binding Height to a slider or text box without range validation; NaN propagating from a division or default-initialized double; copying values from a unit-converted source.
Related errors
- SR.InvalidDrawingAttributesWidth
- InvalidDrawingAttributesHeight
- InvalidDrawingAttributesWidth
- Argument out of range (end not contained in view)
- Argument out of range (position does not map to a line)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/aac76a1492fc6acc.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs:161
/// The height of the StylusTip
/// </summary>
public double Height
{
get
{
//prevent boxing / unboxing if possible
if (!_extendedProperties.Contains(KnownIds.StylusHeight))
{
Debug.Assert(DrawingAttributes.DefaultHeight == (double)GetDefaultDrawingAttributeValue(KnownIds.StylusHeight));
return DrawingAttributes.DefaultHeight;
}
return (double)GetExtendedPropertyBackedProperty(KnownIds.StylusHeight);
}
set
{
if (double.IsNaN(value) || value < MinHeight || value > MaxHeight)
{
throw new ArgumentOutOfRangeException("Height", SR.InvalidDrawingAttributesHeight);
}
//no need to raise change events, they will bubble up from the EPC
//underneath us
SetExtendedPropertyBackedProperty(KnownIds.StylusHeight, value);
}
}
/// <summary>
/// The width of the StylusTip
/// </summary>
public double Width
{
get
{
//prevent boxing / unboxing if possible
if (!_extendedProperties.Contains(KnownIds.StylusWidth))
{
Debug.Assert(DrawingAttributes.DefaultWidth == (double)GetDefaultDrawingAttributeValue(KnownIds.StylusWidth));View on GitHub (pinned to 81131a70a4)