{"record":{"id":"505e61b2be3d7380","repo":"dotnet/wpf","slug":"the-specified-applicationgesture-is-not-valid","errorCode":null,"errorMessage":"The specified ApplicationGesture is not valid.","messagePattern":"The specified ApplicationGesture is not valid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs","lineNumber":218,"sourceCode":"                {\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\n                if (gestures.Contains(gesture))\n                {\n                    throw new ArgumentException(SR.DuplicateApplicationGestureFound, nameof(applicationGestures));\n                }\n\n                gestures.Add(gesture);\n            }\n\n            // AllGesture cannot be specified with other gestures","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs#L200-L236","documentation":"GetApplicationGestureArrayAndVerify validates each element of the ApplicationGesture array with ApplicationGestureHelper.IsDefined before enabling it. Any value outside the defined enum range — such as raw numeric values or uninitialized enums — throws ArgumentException (SR.ApplicationGestureIsInvalid).","triggerScenarios":"Assigning EnabledGestures containing an ApplicationGesture value not defined by the enum (e.g. cast from an invalid int, or a deserialized/garbage value).","commonSituations":"Restoring gesture settings from persisted config or user data that stored raw integers; interop code casting foreign enums into ApplicationGesture.","solutions":["Filter entries with ApplicationGestureHelper.IsDefined(gesture) before assigning","Sanitize persisted/config values and skip or fix undefined enum values","Use only enum members compiled into ApplicationGesture; never cast unchecked ints","Log and drop invalid values instead of passing them through"],"exampleFix":"// before\nrecognizer.EnabledGestures = loadedGestures; // from persisted ints\n// after\nrecognizer.EnabledGestures = loadedGestures.Where(ApplicationGestureHelper.IsDefined).ToArray();","handlingStrategy":"validation","validationCode":"if (gestures.Any(g => !ApplicationGestureHelper.IsDefined(g)))\n    throw new ArgumentException(\"Contains undefined ApplicationGesture values\", nameof(gestures));","typeGuard":"static bool AllDefined(ApplicationGesture[] g) => g.All(ApplicationGestureHelper.IsDefined);","tryCatchPattern":"try { recognizer.EnabledGestures = gestures; }\ncatch (ArgumentException) { recognizer.EnabledGestures = new[]{ ApplicationGesture.AllGestures }; }","preventionTips":["Never cast raw ints to ApplicationGesture from persisted data unchecked","Sanitize config-loaded enum values with IsDefined","Prefer serializing gesture names (strings) instead of numeric values"],"tags":["wpf","ink","enum-validation","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}