{"record":{"id":"9ac1957dacd295ba","repo":"dotnet/wpf","slug":"sr-format-sr-enum-invalid-nameof-systemgesture","errorCode":null,"errorMessage":"SR.Format(SR.Enum_Invalid, nameof(systemGesture))","messagePattern":"SR\\.Format\\(SR\\.Enum_Invalid, nameof\\(systemGesture\\)\\)","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusSystemGestureInputReport.cs","lineNumber":157,"sourceCode":"            int timestamp,\n            PresentationSource inputSource,\n            PenContext penContext,\n            int tabletId,\n            int stylusDeviceId,\n            SystemGesture systemGesture,\n            int gestureX,\n            int gestureY,\n            int buttonState)\n            : base(mode, timestamp, inputSource, penContext, RawStylusActions.SystemGesture, tabletId, stylusDeviceId, Array.Empty<int>())\n        {\n            Initialize(systemGesture, gestureX, gestureY, buttonState);\n        }\n\n        private void Initialize(SystemGesture systemGesture, int gestureX, int gestureY, int buttonState)\n        {\n            if (!RawStylusSystemGestureInputReport.IsValidSystemGesture(systemGesture, true, true))\n            {\n                throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, nameof(systemGesture)));\n            }\n\n            _id = systemGesture;\n            _gestureX = gestureX;\n            _gestureY = gestureY;\n            _buttonState = buttonState;\n        }\n\n        /////////////////////////////////////////////////////////////////////\n        /// <summary>\n        ///     Read-only access to the stylus gesture id.\n        /// </summary>\n        internal SystemGesture SystemGesture { get { return _id; } }\n\n        /////////////////////////////////////////////////////////////////////\n        /// <summary>\n        ///     Read-only access to the X location of the system gesture\n        ///      in tablet device coordinates.","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusSystemGestureInputReport.cs#L139-L175","documentation":"RawStylusSystemGestureInputReport.Initialize validates that the SystemGesture is one of the recognized gestures recognized by IsValidSystemGesture (with the two boolean gates). An unrecognized gesture throws InvalidEnumArgumentException with SR.Enum_Invalid.","triggerScenarios":"Constructing a RawStylusSystemGestureInputReport with a systemGesture value that fails IsValidSystemGesture(gesture, true, true) — i.e. not one of the supported gestures accepted under those constraints (e.g. (SystemGesture)99, or a gesture excluded by the gate flags such as a two-finger/tap-only gesture where not permitted).","commonSituations":"Custom pen input providers or test fakes synthesizing system-gesture reports with arbitrary integer gestures; porting from WinTab/REAL-time stylus where the gesture id spaces differ.","solutions":["Pass only supported SystemGesture values (Tap, DoubleTap, RightTap, Drag, RightDrag, HoldEnter, HoldLeave, HoverEnter, HoverLeave, Flick, TwoFingerTap, AllGestures)","Validate the gesture before constructing the report (replicate the IsValidSystemGesture check)","Map foreign gesture IDs to WPF SystemGesture values explicitly instead of casting raw ints"],"exampleFix":"// before\nvar report = new RawStylusSystemGestureInputReport(mode, ts, src, (SystemGesture)0x55, x, y, btn);\n// after\nvar gesture = (SystemGesture)0x55;\nif (!Enum.IsDefined(gesture)) throw new ArgumentException(nameof(systemGesture));\nvar report = new RawStylusSystemGestureInputReport(mode, ts, src, gesture, x, y, btn);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(SystemGesture), gesture)) throw new ArgumentException(nameof(gesture));","typeGuard":null,"tryCatchPattern":"try { new RawStylusSystemGestureInputReport(...); } catch (InvalidEnumArgumentException) { /* map/normalize gesture id */ }","preventionTips":["Use only documented SystemGesture values","Explicitly map external gesture IDs instead of casting raw integers"],"tags":["wpf","stylus","enum","gesture"],"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"}