{"record":{"id":"3f8ce78b9239eb28","repo":"dotnet/wpf","slug":"sr-emptyarray-strokecollection2","errorCode":null,"errorMessage":"SR.EmptyArray","messagePattern":"SR\\.EmptyArray","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs","lineNumber":225,"sourceCode":"                }\n            }\n\n            return hits;\n        }\n\n        /// <summary>\n        /// Clips out all ink outside a given lasso\n        /// </summary>\n        /// <param name=\"lassoPoints\">lasso</param>\n        public void Clip(IEnumerable<Point> lassoPoints)\n        {\n            // Check the input parameters\n            ArgumentNullException.ThrowIfNull(lassoPoints);\n\n            int length = IEnumerablePointHelper.GetCount(lassoPoints);\n            if (length == 0)\n            {\n                throw new ArgumentException(SR.EmptyArray);\n            }\n\n            if (length < 3)\n            {\n                //\n                // if you're clipping with a point or a line with \n                // two points, it doesn't matter where the line is or if it\n                // intersects any of the strokes, the point or line has no region\n                // so technically everything in the strokecollection\n                // should be removed\n                //\n                this.Clear(); //raises the appropriate events\n                return;\n            }\n\n            Lasso lasso = new SingleLoopLasso();\n            lasso.AddPoints(lassoPoints);\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs#L207-L243","documentation":"StrokeCollection.Clip(IEnumerable<Point> lassoPoints) rejects an empty point sequence with ArgumentException(SR.EmptyArray). Clipping ink requires a lasso polygon of at least one point (fewer than 3 points is handled as a degenerate line/point clip, but zero points is invalid).","triggerScenarios":"Calling Clip with an empty list/array of points, e.g. a lasso selection that never received points because the mouse gesture ended before any movement, or deserializing an empty persisted selection.","commonSituations":"Lasso gesture completed without capture; clearing the point buffer between strokes and calling Clip unconditionally; data binding to an empty point collection.","solutions":["Guard before calling: if (points.Count == 0) return; ","Only invoke Clip when the lasso gesture produced at least one point","Treat an empty selection as a no-op in the calling code"],"exampleFix":"// before\ninkCanvas.Strokes.Clip(lassoPoints); // throws when empty\n// after\nif (lassoPoints != null && lassoPoints.Any())\n{\n    inkCanvas.Strokes.Clip(lassoPoints);\n}","handlingStrategy":"validation","validationCode":"if (lassoPoints == null || !lassoPoints.Any()) return;","typeGuard":"bool HasPoints(IEnumerable<Point> p) => p != null && p.Any();","tryCatchPattern":"try { strokes.Clip(pts); } catch (ArgumentException) { /* empty selection: no-op */ }","preventionTips":["Only run Clip after a gesture that produced points","Treat empty selections as no-ops at the UI layer","Check point count before committing selection operations"],"tags":["wpf","ink","empty-collection","clip"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}