{"record":{"id":"4df70ae4acc2e95f","repo":"dotnet/wpf","slug":"failed-to-set-enabled-gestures","errorCode":null,"errorMessage":"Failed to set enabled gestures.","messagePattern":"Failed to set enabled gestures\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs","lineNumber":103,"sourceCode":"\n        /// <summary>\n        /// Set the enabled gestures\n        /// </summary>\n        /// <param name=\"applicationGestures\"></param>\n        internal ApplicationGesture[] SetEnabledGestures(IEnumerable<ApplicationGesture> applicationGestures)\n        {\n            ObjectDisposedException.ThrowIf(_disposed, typeof(NativeRecognizer));\n\n            //validate and get an array out\n            ApplicationGesture[] enabledGestures =\n                GetApplicationGestureArrayAndVerify(applicationGestures);\n\n            // Set enabled Gestures.\n            int hr = SetEnabledGestures(_hContext, enabledGestures);\n            if (HRESULT.Failed(hr))\n            {\n                //don't throw a com exception here, we don't need to pass out any details\n                throw new InvalidOperationException(SR.UnspecifiedSetEnabledGesturesException);\n            }\n\n            return enabledGestures;\n        }\n\n        /// <summary>\n        /// Recognize the strokes.\n        /// </summary>\n        /// <param name=\"strokes\"></param>\n        /// <returns></returns>\n        internal GestureRecognitionResult[] Recognize(StrokeCollection strokes)\n        {\n            ObjectDisposedException.ThrowIf(_disposed, typeof(NativeRecognizer));\n\n            //\n            // note that we validate this argument from GestureRecognizer \n            // but since this is marked TAS, we want to do it here as well\n            //","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs#L85-L121","documentation":"Gesture recognition is performed through the native Tablet PC ink recognizer via a context handle (SetEnabledGestures P/Invoke). When the native call returns a failing HRESULT, the wrapper throws InvalidOperationException deliberately withholding COM error details because none are useful to surface. It means the native recognizer refused to update its enabled-gesture set.","triggerScenarios":"Calling GestureRecognizer.EnabledGestures setter (SetEnabledGestures) after the native recognizer context handle is invalid, disposed, or when the underlying ink recognition engine (Tablet PC platform / ISF components) is unavailable on the machine.","commonSituations":"Running on machines or in environments (e.g. non-Windows, server SKUs, containers) without the Tablet PC ink recognition service; using a GestureRecognizer whose native context has been disposed or failed to initialize.","solutions":["Verify the Tablet PC / ink recognition components are installed and functional on the target machine","Ensure the GestureRecognizer (and its native context) is still alive and not disposed when setting EnabledGestures","Catch InvalidOperationException around the EnabledGestures assignment and degrade gracefully (disable gesture features)","Re-create the GestureRecognizer instance to get a fresh native context and retry once"],"exampleFix":"// before\nrecognizer.EnabledGestures = new[] { ApplicationGesture.Down };\n// after\ntry { recognizer.EnabledGestures = new[] { ApplicationGesture.Down }; }\ncatch (InvalidOperationException) { /* ink engine unavailable; fall back to no gesture recognition */ }","handlingStrategy":"try-catch","validationCode":"if (recognizer == null) throw new InvalidOperationException(\"Recognizer not initialized\");\n// ensure ink platform present before use\nbool inkAvailable = OperatingSystem.IsWindows();","typeGuard":"static bool HasLiveContext(GestureRecognizer r) => r != null && !r.IsDisposed;","tryCatchPattern":"try { recognizer.EnabledGestures = gestures; }\ncatch (InvalidOperationException ex) { logger.LogWarning(ex, \"Gesture enable failed\"); gestureSupport = false; }","preventionTips":["Check ink-platform availability before enabling gesture features","Keep the recognizer alive for the duration of use; avoid disposing mid-session","Wrap all gesture configuration in a single guarded setup method"],"tags":["wpf","ink","native-interop","gesture-recognition"],"backgroundTag":"internal-invariant-violation","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"}