dotnet/wpf · error · ArgumentException

Duplicate ApplicationGesture values are not allowed.

Error message

Duplicate ApplicationGesture values are not allowed.

What it means

The same validation pass (GetApplicationGestureArrayAndVerify) rejects duplicates: it accumulates gestures in a list and throws ArgumentException (SR.DuplicateApplicationGestureFound) if a gesture already appeared, since the native context expects a set of unique gesture IDs.

Solutions

  1. Deduplicate before assigning: pass through Distinct()
  2. Use HashSet<ApplicationGesture> to build the set
  3. Normalize/merge gesture lists at load time before configuring the recognizer

Example fix

// before
recognizer.EnabledGestures = userGestures.Concat(defaults).ToArray();
// after
recognizer.EnabledGestures = userGestures.Concat(defaults).Distinct().ToArray();
Defensive patterns

Strategy: validation

Validate before calling

gestures = gestures.Distinct().ToArray(); // dedupe before assignment

Type guard

static ApplicationGesture[] Deduped(ApplicationGesture[] g) => g == null ? g : g.Distinct().ToArray();

Try / catch

try { recognizer.EnabledGestures = gestures; }
catch (ArgumentException) { recognizer.EnabledGestures = gestures.Distinct().ToArray(); }

Prevention

When it happens

Trigger: Assigning EnabledGestures where the same ApplicationGesture appears more than once — e.g. appending defaults to user-selected gestures, or concatenating multiple gesture lists.

Common situations: Merging saved preferences with hardcoded defaults; unioning gesture lists without deduplication.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs:230

            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 dupes
                if (gestures.Contains(gesture))
                {
                    throw new ArgumentException(SR.DuplicateApplicationGestureFound, nameof(applicationGestures));
                }

                gestures.Add(gesture);
            }

            // AllGesture cannot be specified with other gestures
            if (foundAllGestures && gestures.Count != 1)
            {
                // no dupes allowed
                throw new ArgumentException(SR.AllGesturesMustExistAlone, nameof(applicationGestures));
            }

            return gestures.ToArray();
        }

        #endregion Internal Methods

        //-------------------------------------------------------------------------------

View on GitHub (pinned to 81131a70a4)