dotnet/wpf · error · InvalidOperationException

SR.GestureRecognizerNotAvailable

Error message

SR.GestureRecognizerNotAvailable

What it means

GestureRecognizer throws InvalidOperationException when no native gesture recognizer is available (_nativeRecognizer == null). On platforms or configurations without ink/gesture recognition support (e.g. non-Windows, or missing tablet/ink runtime components), the recognizer cannot function.

Solutions

  1. Check GestureRecognizer availability before use (e.g. try/catch InvalidOperationException or probe via ApplicationGesture support)
  2. Ensure the app runs on Windows with ink/gesture recognition components installed
  3. Wrap recognition in try-catch and degrade gracefully (skip gesture recognition) when unavailable

Example fix

// before
var results = recognizer.Recognize(stroke);
// after
try { var results = recognizer.Recognize(stroke); }
catch (InvalidOperationException) { /* recognizer not available on this machine */ }
Defensive patterns

Strategy: try-catch

Validate before calling

// availability must be probed at runtime
bool recognizerAvailable = IsGestureRecognizerPresent(); // e.g. wrap first use in try/catch

Type guard

bool RecognizerUsable(GestureRecognizer g) { try { g.GetEnabledGestures(); return true; } catch (InvalidOperationException) { return false; } }

Try / catch

try { results = recognizer.Recognize(strokes); } catch (InvalidOperationException) when (IsNativeRecognizerMissing()) { /* feature unavailable on this machine */ }

Prevention

When it happens

Trigger: Calling SetEnabledGestures, GetEnabledGestures, or Recognize when the native recognizer failed to initialize — typically on systems lacking Ink recognition (no Windows ink components / wrong OS).

Common situations: Running WPF ink tests on CI without ink support; deployment to Windows SKUs without the gesture recognizer; cross-platform or service contexts (no STA/presentation context).

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/GestureRecognizer.cs:250

            _disposed = true;
        }

        #endregion IDisposable

        //-------------------------------------------------------------------------------
        //
        // Private Methods
        //
        //-------------------------------------------------------------------------------

        #region Private Methods
        //verify that there is a recognizer available, throw if not
        private void VerifyRecognizerAvailable()
        {
            if (_nativeRecognizer == null)
            {
                throw new InvalidOperationException(SR.GestureRecognizerNotAvailable);
            }
        }
        
        // Verify whether this object has been disposed.
        private void VerifyDisposed()
        {
            ObjectDisposedException.ThrowIf(_disposed, typeof(GestureRecognizer));
        }

        #endregion Private Methods

        //-------------------------------------------------------------------------------
        //
        // Private Fields
        //
        //-------------------------------------------------------------------------------

        #region Private Fields

View on GitHub (pinned to 81131a70a4)