dotnet/wpf · error · ArgumentException

SR.Manipulation_InvalidManipulationMode

Error message

SR.Manipulation_InvalidManipulationMode

What it means

ManipulationStartingEventArgs.Mode setter throws ArgumentException with SR.Manipulation_InvalidManipulationMode when the assigned Manipulations value contains bits outside ManipulationModes.All. The Mode property only accepts valid ManipulationModes flag combinations. WPF validates the enum mask to prevent meaningless or future-invalid mode bits.

Solutions

  1. Mask the value with ManipulationModes.All before assigning: e.Mode = value & ManipulationModes.All
  2. Assign only named enum members or valid combinations of them
  3. Validate parsed config values against ManipulationModes.All before use

Example fix

// before
e.Mode = (ManipulationModes)rawConfigValue; // may contain invalid bits
// after
ManipulationModes mode = rawConfigValue & ManipulationModes.All;
e.Mode = mode;
Defensive patterns

Strategy: validation

Validate before calling

if ((mode & ~ManipulationModes.All) != 0)
    throw new ArgumentException("Invalid ManipulationModes value", nameof(mode));
e.Mode = mode;

Type guard

static bool IsValidManipulationMode(ManipulationModes m) => (m & ~ManipulationModes.All) == 0;

Try / catch

try { e.Mode = parsedMode; }
catch (ArgumentException) { e.Mode = ManipulationModes.All; }

Prevention

When it happens

Trigger: Assigning e.Mode a value with undefined bits, e.g. (ManipulationModes)0x1000 cast from an int, or an arithmetic result like ManipulationModes.All << 1.

Common situations: Storing ManipulationModes in an int config and casting back without masking; combining modes with bitwise ops that accidentally set undefined high bits.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/ManipulationStartingEventArgs.cs:32

    {
        internal ManipulationStartingEventArgs(
            ManipulationDevice manipulationDevice, 
            int timestamp)
            : base(manipulationDevice, timestamp)
        {
            RoutedEvent = Manipulation.ManipulationStartingEvent;
            Mode = ManipulationModes.All;
            IsSingleTouchEnabled = true;
        }

        public ManipulationModes Mode
        {
            get { return _mode; }
            set
            {
                if ((value & ~ManipulationModes.All) != 0)
                {
                    throw new ArgumentException(SR.Manipulation_InvalidManipulationMode, nameof(value));
                }

                _mode = value;
            }
        }

        /// <summary>
        ///     The ManipulationContainer defines the coordinate space of all parameters
        ///     and values for this manipulation.
        /// </summary>
        public IInputElement ManipulationContainer
        {
            get;
            set;
        }

        /// <summary>
        ///     For single-finger rotation, the pivot is used to determine how to rotate.

View on GitHub (pinned to 81131a70a4)