dotnet/wpf · error · ArgumentOutOfRangeException
SR.InvalidDrawingAttributesWidth
Error message
SR.InvalidDrawingAttributesWidth
What it means
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.
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.
Example fix
// before
da.Width = double.Parse(text); // may be NaN/out of range
// after
if (double.TryParse(text, out var w) && !double.IsNaN(w))
da.Width = Math.Clamp(w, DrawingAttributes.MinWidth, DrawingAttributes.MaxWidth); Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidWidth(double v) => !double.IsNaN(v) && v >= DrawingAttributes.MinWidth && v <= DrawingAttributes.MaxWidth;
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.Width = value; }
catch (ArgumentOutOfRangeException) { da.Width = DrawingAttributes.DefaultWidth; } Prevention
- 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
When it happens
Trigger: Assigning double.NaN, a negative or too-small value, or a value exceeding MaxWidth to DrawingAttributes.Width — typically from user input or dynamic computation.
Common situations: Two-way data binding to an editable field without validation; NaN from failed parsing; unit conversion mistakes (px vs mm) producing extreme values.
Related errors
- SR.InvalidDrawingAttributesHeight
- 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/91a8b91cadb6355f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs:188
/// 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));
return DrawingAttributes.DefaultWidth;
}
return (double)GetExtendedPropertyBackedProperty(KnownIds.StylusWidth);
}
set
{
if (double.IsNaN(value) || value < MinWidth || value > MaxWidth)
{
throw new ArgumentOutOfRangeException("Width", SR.InvalidDrawingAttributesWidth);
}
//no need to raise change events, they will bubble up from the EPC
//underneath us
SetExtendedPropertyBackedProperty(KnownIds.StylusWidth, value);
}
}
/// <summary>
/// When true, ink will be rendered as a series of curves instead of as
/// lines between Stylus sample points. This is useful for smoothing the ink, especially
/// when the person writing the ink has jerky or shaky writing.
/// This value is TRUE by default in the Avalon implementation
/// </summary>
public bool FitToCurve
{
get
{
DrawingFlags flags = (DrawingFlags)GetExtendedPropertyBackedProperty(KnownIds.DrawingFlags);View on GitHub (pinned to 81131a70a4)