dotnet/wpf · error · InvalidEnumArgumentException
SR.Format(SR.Enum_Invalid, nameof(actions))
Error message
SR.Format(SR.Enum_Invalid, nameof(actions))
What it means
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.
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
Example fix
// before var report = new RawStylusInputReport(mode, ts, inputSource, (RawStylusActions)rawInt, penContext, tabletId, stylusId, data); // after var actions = (RawStylusActions)rawInt; if (!RawStylusActionsHelper.IsValid(actions)) throw new ArgumentException(nameof(actions)); var report = new RawStylusInputReport(mode, ts, inputSource, actions, penContext, tabletId, stylusId, data);
Defensive patterns
Strategy: validation
Validate before calling
if (!RawStylusActionsHelper.IsValid(actions)) throw new ArgumentException(nameof(actions));
Try / catch
try { new RawStylusInputReport(...); } catch (InvalidEnumArgumentException) { /* sanitize enum value */ } Prevention
- Only pass defined RawStylusActions values
- Avoid casting raw ints to the enum without validation
- Keep enum values in sync across framework versions
When it happens
Trigger: 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).
Common situations: 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.
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
- Animation_UnrecognizedHandoffBehavior
- captureMode
- InvalidEnumArgumentException for value (TextTrimming)
- InvalidEnumArgumentException("mode", (int)mode…
- InvalidEnumArgumentException("type", (int)type…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0b9af9d8efb47452.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/RawStylusInputReport.cs:181
/// </param>
/// <param name="data">
/// Raw stylus data.
/// </param>
internal RawStylusInputReport(
InputMode mode,
int timestamp,
PresentationSource inputSource,
PenContext penContext,
RawStylusActions actions,
int tabletDeviceId,
int stylusDeviceId,
int[] data)
: this(mode, timestamp, inputSource, actions, () => { return penContext.StylusPointDescription; }, tabletDeviceId, stylusDeviceId, data)
{
// Validate parameters
if (!RawStylusActionsHelper.IsValid(actions))
{
throw new InvalidEnumArgumentException(SR.Format(SR.Enum_Invalid, nameof(actions)));
}
if (actions != RawStylusActions.InRange)
{
ArgumentNullException.ThrowIfNull(data);
}
_actions = actions;
_data = data;
_isSynchronize = false;
_tabletDeviceId = tabletDeviceId;
_stylusDeviceId = stylusDeviceId;
PenContext = penContext;
}
/// <summary>
/// Constructs an instance of the RawStylusInputReport class.
/// </summary>
/// <param name="mode">View on GitHub (pinned to 81131a70a4)