dotnet/wpf · error · ArgumentException

SR.EmptyArray

Error message

SR.EmptyArray

What it means

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).

Solutions

  1. Guard before calling: if (points.Count == 0) return;
  2. Only invoke Clip when the lasso gesture produced at least one point
  3. Treat an empty selection as a no-op in the calling code

Example fix

// before
inkCanvas.Strokes.Clip(lassoPoints); // throws when empty
// after
if (lassoPoints != null && lassoPoints.Any())
{
    inkCanvas.Strokes.Clip(lassoPoints);
}
Defensive patterns

Strategy: validation

Validate before calling

if (lassoPoints == null || !lassoPoints.Any()) return;

Type guard

bool HasPoints(IEnumerable<Point> p) => p != null && p.Any();

Try / catch

try { strokes.Clip(pts); } catch (ArgumentException) { /* empty selection: no-op */ }

Prevention

When it happens

Trigger: 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.

Common situations: Lasso gesture completed without capture; clearing the point buffer between strokes and calling Clip unconditionally; data binding to an empty point collection.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/3f8ce78b9239eb28. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection2.cs:225

                }
            }

            return hits;
        }

        /// <summary>
        /// Clips out all ink outside a given lasso
        /// </summary>
        /// <param name="lassoPoints">lasso</param>
        public void Clip(IEnumerable<Point> lassoPoints)
        {
            // Check the input parameters
            ArgumentNullException.ThrowIfNull(lassoPoints);

            int length = IEnumerablePointHelper.GetCount(lassoPoints);
            if (length == 0)
            {
                throw new ArgumentException(SR.EmptyArray);
            }

            if (length < 3)
            {
                //
                // if you're clipping with a point or a line with 
                // two points, it doesn't matter where the line is or if it
                // intersects any of the strokes, the point or line has no region
                // so technically everything in the strokecollection
                // should be removed
                //
                this.Clear(); //raises the appropriate events
                return;
            }

            Lasso lasso = new SingleLoopLasso();
            lasso.AddPoints(lassoPoints);

View on GitHub (pinned to 81131a70a4)