dotnet/wpf · error · ArgumentOutOfRangeException
SR.InvalidPressureValue
Error message
SR.InvalidPressureValue
What it means
The StylusPoint constructor throws ArgumentOutOfRangeException when the pressureFactor is NaN, negative, or greater than 1.0. Pressure is stored as a float in the normalized range [0, 1]; values outside it are meaningless, so the constructor rejects them (unless validation is disabled internally, as in StylusPointDescription.Reformat).
Solutions
- Normalize raw pressure to [0,1]: pressureFactor = rawPressure / maxPressure.
- Clamp: Math.Clamp(rawPressure, 0f, 1f) before constructing.
- Catch ArgumentOutOfRangeException if untrusted pressure data must be handled gracefully.
Example fix
// before var point = new StylusPoint(x, y, rawPressure); // after float pressure = Math.Clamp(rawPressure / 1024f, 0f, 1f); var point = new StylusPoint(x, y, pressure);
Defensive patterns
Strategy: validation
Validate before calling
if (float.IsNaN(pressureFactor) || pressureFactor < 0f || pressureFactor > 1f)
throw new ArgumentException("pressureFactor must be in [0,1]"); Type guard
static bool IsValidPressure(float p) => !float.IsNaN(p) && p >= 0f && p <= 1f;
Try / catch
try { var p = new StylusPoint(x, y, pf, desc, vals); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "pressureFactor") { /* clamp and retry */ } Prevention
- Always normalize raw device pressure to [0,1]
- Use Math.Clamp on pressure inputs
- Never pass uninitialized float fields as pressure
When it happens
Trigger: Calling new StylusPoint(x, y, pressureFactor, ...) with a pressureFactor that is float.NaN, < 0.0f, or > 1.0f.
Common situations: Passing raw device pressure (e.g. 0-1024 or 0-255 integer ranges) without normalizing to 0..1, or NaN from uninitialized float fields.
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.InvalidMinMaxForButton
- SR.InvalidStylusPointXYNaN
- 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/47cba05ee27d5999.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs:84
int[] additionalValues,
bool validateAdditionalData,
bool validatePressureFactor)
{
if (Double.IsNaN(x))
{
throw new ArgumentOutOfRangeException(nameof(x), SR.InvalidStylusPointXYNaN);
}
if (Double.IsNaN(y))
{
throw new ArgumentOutOfRangeException(nameof(y), SR.InvalidStylusPointXYNaN);
}
//we don't validate pressure when called by StylusPointDescription.Reformat
if (validatePressureFactor &&
(pressureFactor == Single.NaN || pressureFactor < 0.0f || pressureFactor > 1.0f))
{
throw new ArgumentOutOfRangeException(nameof(pressureFactor), SR.InvalidPressureValue);
}
//
// only accept values between MaxXY and MinXY
// we don't throw when passed a value outside of that range, we just silently trunctate
//
_x = GetClampedXYValue(x);
_y = GetClampedXYValue(y);
_stylusPointDescription = stylusPointDescription;
_additionalValues = additionalValues;
_pressureFactor = pressureFactor;
if (validateAdditionalData)
{
//
// called from the public verbose ctor
//
ArgumentNullException.ThrowIfNull(stylusPointDescription);
View on GitHub (pinned to 81131a70a4)