{"record":{"id":"845f4bc416e65bce","repo":"dotnet/wpf","slug":"sr-format-sr-enum-invalid-systemgesture","errorCode":null,"errorMessage":"SR.Format(SR.Enum_Invalid, \"systemGesture\")","messagePattern":"SR\\.Format\\(SR\\.Enum_Invalid, \"systemGesture\"\\)","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusSystemGestureEventArgs.cs","lineNumber":35,"sourceCode":"        ///     Initializes a new instance of the StylusSystemGestureEventArgs class.\n        /// </summary>\n        /// <param name=\"stylusDevice\">\n        ///     The logical Stylus device associated with this event.\n        /// </param>\n        /// <param name=\"timestamp\">\n        ///     The time when the input occured.\n        /// </param>\n        /// <param name=\"systemGesture\"> \n        ///     The type of system gesture.\n        /// </param>\n        public StylusSystemGestureEventArgs(\n            StylusDevice stylusDevice, int timestamp,\n            SystemGesture systemGesture) :\n            base(stylusDevice, timestamp)\n        {\n            if (!RawStylusSystemGestureInputReport.IsValidSystemGesture(systemGesture, false, false))\n            {\n                throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, \"systemGesture\"));\n            }\n            \n            _id        = systemGesture;\n        }\n\n        /////////////////////////////////////////////////////////////////////\n        /// <summary>\n        ///     Initializes a new instance of the StylusSystemGestureEventArgs class.\n        /// </summary>\n        /// <param name=\"stylusDevice\">\n        ///     The logical Stylus device associated with this event.\n        /// </param>\n        /// <param name=\"timestamp\">\n        ///     The time when the input occured.\n        /// </param>\n        /// <param name=\"systemGesture\"> \n        ///     The type of system gesture.\n        /// </param>","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusSystemGestureEventArgs.cs#L17-L53","documentation":"The StylusSystemGestureEventArgs constructor validates the SystemGesture value with RawStylusSystemGestureInputReport.IsValidSystemGesture(gesture, false, false). If the gesture is not a valid system gesture, an InvalidEnumArgumentException with SR.Enum_Invalid for 'systemGesture' is thrown. This API is for framework-internal event construction.","triggerScenarios":"Constructing StylusSystemGestureEventArgs with a SystemGesture value outside the valid set (invalid cast, undefined enum member).","commonSituations":"Replaying or synthesizing stylus events from recorded input data with out-of-range ints cast to SystemGesture; custom input providers injecting gestures.","solutions":["Only pass defined SystemGesture members accepted by IsValidSystemGesture","Validate the gesture value against Enum.IsDefined(typeof(SystemGesture), value) before constructing","Fix integer-to-enum casts in custom input replay code"],"exampleFix":"// before\nvar args = new StylusSystemGestureEventArgs(device, ts, (SystemGesture)999);\n// after\nvar gesture = (SystemGesture)999;\nif (!Enum.IsDefined(typeof(SystemGesture), gesture)) throw new ArgumentException(\"bad gesture\");\nvar args = new StylusSystemGestureEventArgs(device, ts, gesture);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(SystemGesture), gesture)) throw new ArgumentException($\"Invalid SystemGesture: {gesture}\");","typeGuard":"static bool IsValidGesture(SystemGesture g) => Enum.IsDefined(typeof(SystemGesture), g);","tryCatchPattern":"try { var args = new StylusSystemGestureEventArgs(device, ts, gesture); }\ncatch (InvalidEnumArgumentException ex) { /* skip or sanitize the synthesized event */ }","preventionTips":["Never cast raw ints to SystemGesture without Enum.IsDefined","Centralize synthetic event construction behind a validating factory"],"tags":["wpf","stylus","enum"],"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-21T21:30:21.729Z"}