dotnet/wpf · error · ArgumentException
SR.StrokeCollectionCountTooBig
Error message
SR.StrokeCollectionCountTooBig
What it means
GestureRecognizer.Recognize accepts at most 2 strokes per recognition call; larger StrokeCollections throw ArgumentException (SR.StrokeCollectionCountTooBig). Gesture recognition in WPF is defined for one- and two-stroke gestures only.
Solutions
- Split the StrokeCollection into groups of at most 2 strokes and call Recognize per group
- Assert strokes.Count is 1 or 2 before calling
- If multi-stroke analysis is needed, use InkAnalyzer instead of GestureRecognizer
Example fix
// before var results = recognizer.Recognize(allStrokes); // after foreach (var chunk in Chunk(allStrokes, 2)) results.AddRange(recognizer.Recognize(chunk));
Defensive patterns
Strategy: validation
Validate before calling
if (strokes == null || strokes.Count == 0 || strokes.Count > 2) return; // invalid input for Recognize
Type guard
static bool CanRecognize(StrokeCollection s) => s != null && s.Count is >= 1 and <= 2;
Try / catch
try { results = recognizer.Recognize(strokes); } catch (ArgumentException) { results = EmptyResults; } Prevention
- Chunk stroke collections into pairs before recognition
- Remember GestureRecognizer is per-gesture (1–2 strokes), not per-document
- Use InkAnalyzer for larger-scale ink analysis
When it happens
Trigger: Calling recognizer.Recognize(strokes) (or CriticalRecognize) with strokes.Count > 2.
Common situations: Passing an entire ink page's strokes instead of individual gestures; batching strokes for performance and exceeding the limit; misunderstanding that the API is per-gesture, not per-document.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- ExtendedProperty is already part of the…
- Failed to set enabled gestures.
- Gesture recognition failed.
- GUID cannot be empty.
- InvalidMatrixContainsInfinity
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c803e98326cb3677.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs:164
/// <returns></returns>
// Built into Core, also used by Framework.
internal ReadOnlyCollection<GestureRecognitionResult> CriticalRecognize(StrokeCollection strokes)
{
return RecognizeImpl(strokes);
}
/// <summary>
/// Performs gesture recognition on the StrokeCollection if a gesture recognizer
/// is present and installed on the system.
/// </summary>
/// <param name="strokes">The StrokeCollection to perform gesture recognition on</param>
/// <returns></returns>
private ReadOnlyCollection<GestureRecognitionResult> RecognizeImpl(StrokeCollection strokes)
{
ArgumentNullException.ThrowIfNull(strokes);
if (strokes.Count > 2)
{
throw new ArgumentException(SR.StrokeCollectionCountTooBig, nameof(strokes));
}
VerifyAccess();
VerifyDisposed();
VerifyRecognizerAvailable();
return new ReadOnlyCollection<GestureRecognitionResult>(_nativeRecognizer.Recognize(strokes));
}
#endregion Public Methods
//-------------------------------------------------------------------------------
//
// Public Properties
//
//-------------------------------------------------------------------------------
View on GitHub (pinned to 81131a70a4)