{"record":{"id":"ad1fa7b93337557a","repo":"dotnet/wpf","slug":"invalidenumargumentexception-actions-int-actions-typeof-ad1fa7","errorCode":null,"errorMessage":"InvalidEnumArgumentException(\"actions\", (int)actions, typeof(RawMouseActions))","messagePattern":"InvalidEnumArgumentException\\(\"actions\", \\(int\\)actions, typeof\\(RawMouseActions\\)\\)","errorType":"exception","errorClass":"InvalidEnumArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/RawMouseInputReport.cs","lineNumber":55,"sourceCode":"        /// </param>\n        /// <param name=\"wheel\">\n        ///     If wheel delta being reported.\n        /// </param>\n        /// <param name=\"extraInformation\">\n        ///     Any extra information being provided along with the input.\n        /// </param>\n        public RawMouseInputReport(\n            InputMode mode,\n            int timestamp, \n            PresentationSource inputSource,\n            RawMouseActions actions, \n            int x, \n            int y, \n            int wheel, \n            IntPtr extraInformation) : base(inputSource, InputType.Mouse, mode, timestamp)\n        {\n            if (!IsValidRawMouseActions(actions))\n                throw new System.ComponentModel.InvalidEnumArgumentException(\"actions\", (int)actions, typeof(RawMouseActions));\n\n            /* we pass a null state from MouseDevice.PreProcessorInput, so null is valid value for state */\n            _actions = actions;\n            _x = x;\n            _y = y;\n            _wheel = wheel;\n            _extraInformation = extraInformation;\n        }\n\n        /// <summary>\n        ///     Read-only access to the set of actions that were reported.\n        /// </summary>\n        public RawMouseActions Actions {get {return _actions;}}\n\n        /// <summary>\n        ///     Read-only access to the horizontal position that was reported.\n        /// </summary>\n        public int X {get {return _x;}}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/RawMouseInputReport.cs#L37-L73","documentation":"The RawMouseInputReport constructor validates the actions parameter against IsValidRawMouseActions and throws InvalidEnumArgumentException when the value is not a valid RawMouseActions combination. Only defined mouse-report actions (ReportMove, AbsoluteMove, ReportWheel, RelativeMove, Activate, etc.) may be supplied; a null state is allowed, but the actions value must still be valid.","triggerScenarios":"Passing an undefined or illegal combination of RawMouseActions flags to the constructor — typically from casting raw integer mouse data, setting AbsoluteMove without valid coordinates semantics, or passing 0.","commonSituations":"Custom mouse-input synthesis, automation/testing frameworks generating RawMouseInputReport, interop layers translating Win32 mouse messages without proper enum mapping.","solutions":["Build actions from named RawMouseActions flags only; never cast unchecked ints.","Check the value with IsValidRawMouseActions/Enum.IsDefined-style validation before constructing.","Ensure flag combinations are legal (e.g. don't combine AbsoluteMove with RelativeMove improperly).","Update interop mappings after upgrading WPF versions in case the enum changed."],"exampleFix":"// before\nvar actions = (RawMouseActions)rawFlags;\nvar report = new RawMouseInputReport(..., actions, x, y, wheel, extra); // throws for bad flags\n\n// after\nvar actions = move ? RawMouseActions.AbsoluteMove : RawMouseActions.ReportMove;\nvar report = new RawMouseInputReport(..., actions, x, y, wheel, extra);","handlingStrategy":"validation","validationCode":"static bool IsValidRawMouseActionsValue(RawMouseActions a) =>\n    Enum.IsDefined(typeof(RawMouseActions), a);\n// then:\nif (!IsValidRawMouseActionsValue(actions))\n    actions = RawMouseActions.AbsoluteMove;","typeGuard":"bool TryGetMouseActions(int raw, out RawMouseActions actions)\n{\n    actions = (RawMouseActions)raw;\n    return Enum.IsDefined(typeof(RawMouseActions), actions);\n}","tryCatchPattern":"try\n{\n    var report = new RawMouseInputReport(src, mode, ts, actions, x, y, wheel, extra);\n}\ncatch (InvalidEnumArgumentException ex)\n{\n    Log($\"Invalid RawMouseActions: {ex}\");\n}","preventionTips":["Build actions from named flags (AbsoluteMove, ReportMove, ReportWheel, Activate).","Never pass raw interop integers unchecked into the enum.","Keep legal flag combinations (don't mix Absolute and Relative moves).","Re-verify mappings after any WPF version upgrade."],"tags":["wpf","input","mouse","enum","argument-validation"],"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"}