dotnet/wpf · error · ArgumentException
The ApplicationGesture array must contain at least one…
Error message
The ApplicationGesture array must contain at least one member.
What it means
When setting GestureRecognizer.EnabledGestures, the value is funneled through GetApplicationGestureArrayAndVerify, which rejects an empty ApplicationGesture array with ArgumentException (SR.ApplicationGestureArrayLengthIsZero). An empty set is meaningless to the native recognizer, so it is disallowed up front.
Solutions
- Always pass at least one ApplicationGesture (use ApplicationGesture.AllGestures to enable everything)
- Check the array length before assigning and skip assignment if empty
- To effectively disable gestures, unsubscribe from gesture events or dispose the recognizer instead
- Throw or log a configuration error upstream when the gesture list computes to empty
Example fix
// before recognizer.EnabledGestures = GetEnabledGestures(); // may be empty // after var gestures = GetEnabledGestures(); if (gestures.Length > 0) recognizer.EnabledGestures = gestures;
Defensive patterns
Strategy: validation
Validate before calling
if (gestures == null || gestures.Length == 0)
throw new ArgumentException("At least one ApplicationGesture is required", nameof(gestures)); Type guard
static bool IsValidGestureSet(ApplicationGesture[] g) => g != null && g.Length > 0;
Try / catch
try { recognizer.EnabledGestures = gestures; }
catch (ArgumentException ex) { logger.LogError(ex, "Empty gesture set"); } Prevention
- Use ApplicationGesture.AllGestures when you want everything enabled
- Never use an empty array to 'disable' gestures — remove the recognizer instead
- Validate dynamically-built gesture lists before assignment
When it happens
Trigger: Assigning EnabledGestures an empty array or a collection whose count is 0 (e.g. a filtered list where all gestures were removed).
Common situations: Building the gesture list dynamically and forgetting the empty case; disabling all gestures by passing an empty array instead of removing the recognizer.
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
- Duplicate ApplicationGesture values are not allowed.
- If AllGestures is specified, it must be the only…
- InkSerializedFormat operation failed.
- Invalid argument passed to ReliableRead
- Maximum number of strokes is two.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/75e5828e7d033632.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs:209
//we need to make a disconnected copy
ICollection<ApplicationGesture> collection = applicationGestures as ICollection<ApplicationGesture>;
if (collection != null)
{
count = (uint)collection.Count;
}
else
{
foreach (ApplicationGesture gesture in applicationGestures)
{
count++;
}
}
// Cannot be empty
if (count == 0)
{
// An empty array is not allowed.
throw new ArgumentException(SR.ApplicationGestureArrayLengthIsZero, nameof(applicationGestures));
}
bool foundAllGestures = false;
List<ApplicationGesture> gestures = new List<ApplicationGesture>();
foreach (ApplicationGesture gesture in applicationGestures)
{
if (!ApplicationGestureHelper.IsDefined(gesture))
{
throw new ArgumentException(SR.ApplicationGestureIsInvalid, nameof(applicationGestures));
}
//check for allgestures
if (gesture == ApplicationGesture.AllGestures)
{
foundAllGestures = true;
}
//check for dupesView on GitHub (pinned to 81131a70a4)