{"record":{"id":"0b9af9d8efb47452","repo":"dotnet/wpf","slug":"sr-format-sr-enum-invalid-nameof-actions","errorCode":null,"errorMessage":"SR.Format(SR.Enum_Invalid, nameof(actions))","messagePattern":"SR\\.Format\\(SR\\.Enum_Invalid, nameof\\(actions\\)\\)","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusInputReport.cs","lineNumber":181,"sourceCode":"        /// </param>\n        /// <param name=\"data\">\n        ///     Raw stylus data.\n        /// </param>\n        internal RawStylusInputReport(\n            InputMode mode,\n            int timestamp,\n            PresentationSource inputSource,\n            PenContext penContext,\n            RawStylusActions actions,\n            int tabletDeviceId,\n            int stylusDeviceId,\n            int[] data)\n            : this(mode, timestamp, inputSource, actions, () => { return penContext.StylusPointDescription; }, tabletDeviceId, stylusDeviceId, data)\n        {\n            // Validate parameters\n            if (!RawStylusActionsHelper.IsValid(actions))\n            {\n                throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, nameof(actions)));\n            }\n            if (actions != RawStylusActions.InRange)\n            {\n                ArgumentNullException.ThrowIfNull(data);\n            }\n\n            _actions = actions;\n            _data = data;\n            _isSynchronize = false;\n            _tabletDeviceId = tabletDeviceId;\n            _stylusDeviceId = stylusDeviceId;\n            PenContext = penContext;\n        }\n\n        /// <summary>\n        ///     Constructs an instance of the RawStylusInputReport class.\n        /// </summary>\n        /// <param name=\"mode\">","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusInputReport.cs#L163-L199","documentation":"This RawStylusInputReport constructor validates that the RawStylusActions value is a defined/valid combination via RawStylusActionsHelper.IsValid. An undefined enum value throws InvalidEnumArgumentException with SR.Enum_Invalid.","triggerScenarios":"Constructing a RawStylusInputReport (PenContext overload) passing an actions value that is not a valid RawStylusActions bitmask, such as a cast from an arbitrary int (e.g. (RawStylusActions)999).","commonSituations":"Custom pen/stylus test harnesses or interop code fabricating input reports with hand-picked integer action values; deserializing persisted reports where the enum value came from a different framework version.","solutions":["Pass only defined RawStylusActions values (Down, Move, Up, InRange, InAirMove, etc.) or valid combinations","Validate with RawStylusActionsHelper.IsValid(actions) (or Enum.IsDefined on your own flags) before constructing","Audit casts of raw integers to RawStylusActions"],"exampleFix":"// before\nvar report = new RawStylusInputReport(mode, ts, inputSource, (RawStylusActions)rawInt, penContext, tabletId, stylusId, data);\n// after\nvar actions = (RawStylusActions)rawInt;\nif (!RawStylusActionsHelper.IsValid(actions)) throw new ArgumentException(nameof(actions));\nvar report = new RawStylusInputReport(mode, ts, inputSource, actions, penContext, tabletId, stylusId, data);","handlingStrategy":"validation","validationCode":"if (!RawStylusActionsHelper.IsValid(actions)) throw new ArgumentException(nameof(actions));","typeGuard":null,"tryCatchPattern":"try { new RawStylusInputReport(...); } catch (InvalidEnumArgumentException) { /* sanitize enum value */ }","preventionTips":["Only pass defined RawStylusActions values","Avoid casting raw ints to the enum without validation","Keep enum values in sync across framework versions"],"tags":["wpf","stylus","enum","invalid-argument"],"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"}