dotnet/wpf · error · InvalidEnumArgumentException
InvalidEnumArgumentException("actions", (int)actions…
Error message
InvalidEnumArgumentException("actions", (int)actions, typeof(RawMouseActions)) What it means
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.
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.
Example fix
// before var actions = (RawMouseActions)rawFlags; var report = new RawMouseInputReport(..., actions, x, y, wheel, extra); // throws for bad flags // after var actions = move ? RawMouseActions.AbsoluteMove : RawMouseActions.ReportMove; var report = new RawMouseInputReport(..., actions, x, y, wheel, extra);
Defensive patterns
Strategy: validation
Validate before calling
static bool IsValidRawMouseActionsValue(RawMouseActions a) =>
Enum.IsDefined(typeof(RawMouseActions), a);
// then:
if (!IsValidRawMouseActionsValue(actions))
actions = RawMouseActions.AbsoluteMove; Type guard
bool TryGetMouseActions(int raw, out RawMouseActions actions)
{
actions = (RawMouseActions)raw;
return Enum.IsDefined(typeof(RawMouseActions), actions);
} Try / catch
try
{
var report = new RawMouseInputReport(src, mode, ts, actions, x, y, wheel, extra);
}
catch (InvalidEnumArgumentException ex)
{
Log($"Invalid RawMouseActions: {ex}");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Custom mouse-input synthesis, automation/testing frameworks generating RawMouseInputReport, interop layers translating Win32 mouse messages without proper enum mapping.
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
- InvalidEnumArgumentException("action", (int)action…
- InvalidEnumArgumentException("actions", (int)actions…
- InvalidEnumArgumentException("button", (int)button…
- InvalidEnumArgumentException("captureMode"…
- InvalidEnumArgumentException("targets", (int)targets…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ad1fa7b93337557a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/RawMouseInputReport.cs:55
/// </param>
/// <param name="wheel">
/// If wheel delta being reported.
/// </param>
/// <param name="extraInformation">
/// Any extra information being provided along with the input.
/// </param>
public RawMouseInputReport(
InputMode mode,
int timestamp,
PresentationSource inputSource,
RawMouseActions actions,
int x,
int y,
int wheel,
IntPtr extraInformation) : base(inputSource, InputType.Mouse, mode, timestamp)
{
if (!IsValidRawMouseActions(actions))
throw new System.ComponentModel.InvalidEnumArgumentException("actions", (int)actions, typeof(RawMouseActions));
/* we pass a null state from MouseDevice.PreProcessorInput, so null is valid value for state */
_actions = actions;
_x = x;
_y = y;
_wheel = wheel;
_extraInformation = extraInformation;
}
/// <summary>
/// Read-only access to the set of actions that were reported.
/// </summary>
public RawMouseActions Actions {get {return _actions;}}
/// <summary>
/// Read-only access to the horizontal position that was reported.
/// </summary>
public int X {get {return _x;}}View on GitHub (pinned to 81131a70a4)