dotnet/wpf · error · InvalidOperationException

SR.Manipulation_ManipulationNotActive

Error message

SR.Manipulation_ManipulationNotActive

What it means

Manipulation.CompleteManipulation requires an active manipulation on the element. If TryCompleteManipulation fails (no ManipulationDevice is tracking the element), it throws InvalidOperationException with Manipulation_ManipulationNotActive.

Solutions

  1. Use the internal-style check first: track whether manipulation is active before calling, or wrap in try-catch for InvalidOperationException
  2. Call CompleteManipulation only in response to live touch input (e.g. before ManipulationCompleted fires)
  3. Track manipulation state via ManipulationStarted/ManipulationCompleted events

Example fix

// before
Manipulation.CompleteManipulation(element);
// after
if (isManipulating) // tracked via ManipulationStarted/Completed events
    Manipulation.CompleteManipulation(element);
Defensive patterns

Strategy: try-catch

Try / catch

try { Manipulation.CompleteManipulation(element); } catch (InvalidOperationException) { /* no active manipulation; safe to ignore */ }

Prevention

When it happens

Trigger: Calling Manipulation.CompleteManipulation(element) when no touch manipulation is currently active on that element (manipulation already completed, never started, or released).

Common situations: Programmatically ending a touch gesture after the user already lifted their finger; calling completion from async code where the manipulation ended first; double-completing in response to ManipulationCompleted.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Manipulation.cs:73

        /// <param name="element">The element on which there is an active manipulation.</param>
        public static void StartInertia(UIElement element)
        {
            ArgumentNullException.ThrowIfNull(element);

            ManipulationDevice device = ManipulationDevice.GetManipulationDevice(element);
            device?.CompleteManipulation(withInertia: true);
        }

        /// <summary>
        ///     If a manipulation is active, forces the manipulation to complete.
        /// </summary>
        /// <param name="element">The element on which there is an active manipulation.</param>
        public static void CompleteManipulation(UIElement element)
        {
            ArgumentNullException.ThrowIfNull(element);
            if (!TryCompleteManipulation(element))
            {
                throw new InvalidOperationException(SR.Manipulation_ManipulationNotActive);
            }
        }

        internal static bool TryCompleteManipulation(UIElement element)
        {
            ManipulationDevice device = ManipulationDevice.GetManipulationDevice(element);
            if (device != null)
            {
                device.CompleteManipulation(withInertia: false);
                return true;
            }

            return false;
        }

        /// <summary>
        ///     Changes the manipulation mode of an active manipulation.
        /// </summary>

View on GitHub (pinned to 81131a70a4)