{"record":{"id":"9263d9e57c57e893","repo":"dotnet/wpf","slug":"sr-invalidstyluspointxynan","errorCode":null,"errorMessage":"SR.InvalidStylusPointXYNaN","messagePattern":"SR\\.InvalidStylusPointXYNaN","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs","lineNumber":72,"sourceCode":"            : this(x, y, pressureFactor, stylusPointDescription, additionalValues, true, true)\n        {\n        }\n\n        /// <summary>\n        /// internal ctor\n        /// </summary>\n        internal StylusPoint(   \n            double x, \n            double y, \n            float pressureFactor, \n            StylusPointDescription stylusPointDescription, \n            int[] additionalValues, \n            bool validateAdditionalData,\n            bool validatePressureFactor)\n        {\n            if (Double.IsNaN(x))\n            {\n                throw new ArgumentOutOfRangeException(nameof(x), SR.InvalidStylusPointXYNaN);\n            }\n            if (Double.IsNaN(y))\n            {\n                throw new ArgumentOutOfRangeException(nameof(y), SR.InvalidStylusPointXYNaN);\n            }\n\n\n            //we don't validate pressure when called by StylusPointDescription.Reformat\n            if (validatePressureFactor &&\n                (pressureFactor == Single.NaN || pressureFactor < 0.0f || pressureFactor > 1.0f))\n            {\n                throw new ArgumentOutOfRangeException(nameof(pressureFactor), SR.InvalidPressureValue);\n            }\n            //\n            // only accept values between MaxXY and MinXY\n            // we don't throw when passed a value outside of that range, we just silently trunctate\n            //\n            _x = GetClampedXYValue(x);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs#L54-L90","documentation":"The StylusPoint constructor throws ArgumentOutOfRangeException when the x coordinate is double.NaN. StylusPoint coordinates must be real numbers; NaN cannot be represented in packet data, so the constructor rejects it before clamping. This guard exists because NaN silently corrupts downstream geometry and hit-testing.","triggerScenarios":"Calling new StylusPoint(x, y) or new StylusPoint(x, y, pressureFactor, stylusPointDescription, additionalValues, ...) with a double.NaN value for the x parameter.","commonSituations":"Computing coordinates from division or transforms that yield NaN (e.g. 0/0 from a scale calculation), or passing through unvalidated sensor/digitizer data where a missing sample is encoded as NaN.","solutions":["Check double.IsNaN(x) before constructing the StylusPoint and substitute a valid value or skip the point.","Trace the origin of the x value (division, Math operations, external data) and fix the source that produces NaN.","Catch ArgumentOutOfRangeException if NaN input is expected and handle the point as invalid."],"exampleFix":"// before\nvar point = new StylusPoint(rawX, rawY);\n// after\nif (!double.IsNaN(rawX) && !double.IsNaN(rawY))\n{\n    var point = new StylusPoint(rawX, rawY);\n}","handlingStrategy":"validation","validationCode":"if (double.IsNaN(x)) throw new ArgumentException(\"x must be a finite value\");\nvar point = new StylusPoint(x, y);","typeGuard":"static bool IsValidX(double x) => !double.IsNaN(x) && !double.IsInfinity(x);","tryCatchPattern":"try { var p = new StylusPoint(x, y); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"x\") { /* treat point as invalid */ }","preventionTips":["Validate all coordinates before constructing StylusPoint","Guard divisions that could yield NaN","Sanitize external or sensor coordinate data"],"tags":["wpf","stylus","argumentoutofrange","nan"],"backgroundTag":"argument-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}