{"record":{"id":"75e5828e7d033632","repo":"dotnet/wpf","slug":"the-applicationgesture-array-must-contain-at-least-one","errorCode":null,"errorMessage":"The ApplicationGesture array must contain at least one member.","messagePattern":"The ApplicationGesture array must contain at least one member\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs","lineNumber":209,"sourceCode":"            //we need to make a disconnected copy\n            ICollection<ApplicationGesture> collection = applicationGestures as ICollection<ApplicationGesture>;\n            if (collection != null)\n            {\n                count = (uint)collection.Count;\n            }\n            else\n            {\n                foreach (ApplicationGesture gesture in applicationGestures)\n                {\n                    count++;\n                }\n            }\n\n            // Cannot be empty\n            if (count == 0)\n            {\n                // An empty array is not allowed.\n                throw new ArgumentException(SR.ApplicationGestureArrayLengthIsZero, nameof(applicationGestures));\n            }\n\n            bool foundAllGestures = false;\n            List<ApplicationGesture> gestures = new List<ApplicationGesture>();\n            foreach (ApplicationGesture gesture in applicationGestures)\n            {\n                if (!ApplicationGestureHelper.IsDefined(gesture))\n                {\n                    throw new ArgumentException(SR.ApplicationGestureIsInvalid, nameof(applicationGestures));\n                }\n\n                //check for allgestures\n                if (gesture == ApplicationGesture.AllGestures)\n                {\n                    foundAllGestures = true;\n                }\n\n                //check for dupes","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs#L191-L227","documentation":"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.","triggerScenarios":"Assigning EnabledGestures an empty array or a collection whose count is 0 (e.g. a filtered list where all gestures were removed).","commonSituations":"Building the gesture list dynamically and forgetting the empty case; disabling all gestures by passing an empty array instead of removing the recognizer.","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"],"exampleFix":"// before\nrecognizer.EnabledGestures = GetEnabledGestures(); // may be empty\n// after\nvar gestures = GetEnabledGestures();\nif (gestures.Length > 0) recognizer.EnabledGestures = gestures;","handlingStrategy":"validation","validationCode":"if (gestures == null || gestures.Length == 0)\n    throw new ArgumentException(\"At least one ApplicationGesture is required\", nameof(gestures));","typeGuard":"static bool IsValidGestureSet(ApplicationGesture[] g) => g != null && g.Length > 0;","tryCatchPattern":"try { recognizer.EnabledGestures = gestures; }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Empty gesture set\"); }","preventionTips":["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"],"tags":["wpf","ink","argument-validation","empty-collection"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}