{"record":{"id":"0b1a05bbf8a1f0df","repo":"dotnet/wpf","slug":"argumentoutofrangeexception-percentagewithinlasso","errorCode":null,"errorMessage":"ArgumentOutOfRangeException(percentageWithinLasso)","messagePattern":"ArgumentOutOfRangeException\\(percentageWithinLasso\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs","lineNumber":84,"sourceCode":"                throw new ArgumentOutOfRangeException(nameof(diameter), SR.InvalidDiameter);\n            }\n            return PointHitTest(point, new EllipseStylusShape(diameter, diameter));\n        }\n\n        /// <summary>\n        /// Hit-testing with lasso\n        /// </summary>\n        /// <param name=\"lassoPoints\">points making the lasso</param>\n        /// <param name=\"percentageWithinLasso\">the margin value to tell whether a stroke\n        /// is in or outside of the rect</param>\n        /// <returns>collection of strokes found inside the rectangle</returns>\n        public StrokeCollection HitTest(IEnumerable<Point> lassoPoints, int percentageWithinLasso)\n        {\n            // Check the input parameters\n            ArgumentNullException.ThrowIfNull(lassoPoints);\n            if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100))\n            {\n                throw new System.ArgumentOutOfRangeException(nameof(percentageWithinLasso));\n            }\n\n            if (IEnumerablePointHelper.GetCount(lassoPoints) < 3)\n            {\n                return new StrokeCollection();\n            }\n\n            Lasso lasso = new SingleLoopLasso();\n            lasso.AddPoints(lassoPoints);\n\n            // Enumerate through the strokes and collect those captured by the lasso.\n            StrokeCollection lassoedStrokes = new StrokeCollection();\n            foreach (Stroke stroke in this)\n            {\n                if (percentageWithinLasso == 0)\n                {\n                    lassoedStrokes.Add(stroke);\n                }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs#L66-L102","documentation":"StrokeCollection.HitTest(IEnumerable<Point>, int percentageWithinLasso) requires the lasso percentage to be between 0 and 100 inclusive. Values outside that range are rejected with ArgumentOutOfRangeException naming percentageWithinLasso. The percentage controls how much of a stroke must lie inside the lasso for it to count as hit.","triggerScenarios":"Calling the lasso HitTest overload with a negative value or a value above 100, e.g. a fraction (0.0-1.0) passed instead of a percentage, or a user-configured sensitivity value that was not clamped.","commonSituations":"Storing hit-test sensitivity as 0-1 in settings and passing it directly; slider controls with Maximum > 100; localization of user input producing values like 150%.","solutions":["Convert any 0-1 fraction to a percentage: (int)Math.Round(fraction * 100)","Clamp before calling: Math.Clamp(percentageWithinLasso, 0, 100)","Fix the UI control bounds so the percentage cannot leave 0-100"],"exampleFix":"// before\nvar hits = strokes.HitTest(lassoPoints, sensitivityFraction); // 0..1\n// after\nint pct = (int)Math.Round(sensitivityFraction * 100);\nvar hits = strokes.HitTest(lassoPoints, pct); // 0..100","handlingStrategy":"validation","validationCode":"int pct = Math.Clamp((int)Math.Round(fraction * 100), 0, 100);","typeGuard":null,"tryCatchPattern":"try { return strokes.HitTest(lasso, pct); } catch (ArgumentOutOfRangeException) { return null; }","preventionTips":["Standardize on 0-100 percentages for all hit-test APIs","Convert 0-1 fractions explicitly at the boundary","Bound slider Maximum at 100"],"tags":["wpf","ink","argument-out-of-range","lasso"],"backgroundTag":"value-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"}