dotnet/wpf · error · ArgumentException
SR.EmptyArrayNotAllowedAsArgument
Error message
SR.EmptyArrayNotAllowedAsArgument
What it means
IncrementalHitTester.AddPoints(IEnumerable<Point>) rejects empty enumerations with ArgumentException (SR.EmptyArrayNotAllowedAsArgument) because hit-testing requires at least one point. It also throws InvalidOperationException if EndHitTesting was already called (error 508).
Solutions
- Check points has at least 1 point before calling AddPoints
- Skip hit-testing entirely for empty point sets
Example fix
// before hitTester.AddPoints(points); // after if (points != null && points.Any()) hitTester.AddPoints(points);
Defensive patterns
Strategy: validation
Validate before calling
if (points == null || !points.Any()) return;
Type guard
static bool HasPoints(IEnumerable<Point> p) => p != null && p.Any();
Try / catch
try { tester.AddPoints(points); } catch (ArgumentException) { /* empty point set — nothing to hit-test */ } catch (InvalidOperationException) { /* EndHitTesting already called */ } Prevention
- Guard all point sources against empty collections
- Early-return from stylus handlers when no packets arrived
- Never feed filtered point lists without a count check
When it happens
Trigger: Calling AddPoints with an empty Point collection/array; calling via AddPoint delegation with an empty source.
Common situations: Hit-testing against a stroke whose collected point list is empty (stroke captured with no samples); passing a filtered point set where the filter removed everything.
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
- ExtendedProperty is already part of the…
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
- InvalidMatrixContainsNaN
- InvalidValueOfType
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8b7dc07753965d59.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/IncrementalHitTester.cs:41
/// Adds a point representing an incremental move of the hit-testing tool
/// </summary>
/// <param name="point">a point that represents an incremental move of the hitting tool</param>
public void AddPoint(Point point)
{
AddPoints(new Point[1] { point });
}
/// <summary>
/// Adds an array of points representing an incremental move of the hit-testing tool
/// </summary>
/// <param name="points">points representing an incremental move of the hitting tool</param>
public void AddPoints(IEnumerable<Point> points)
{
ArgumentNullException.ThrowIfNull(points);
if (IEnumerablePointHelper.GetCount(points) == 0)
{
throw new System.ArgumentException(SR.EmptyArrayNotAllowedAsArgument, nameof(points));
}
if (!_fValid)
{
throw new System.InvalidOperationException(SR.EndHitTestingCalled);
}
System.Diagnostics.Debug.Assert(_strokes != null);
AddPointsCore(points);
}
/// <summary>
/// Adds a StylusPacket representing an incremental move of the hit-testing tool
/// </summary>
/// <param name="stylusPoints">stylusPoints</param>
public void AddPoints(StylusPointCollection stylusPoints)
{View on GitHub (pinned to 81131a70a4)