dotnet/wpf · error · ArgumentException
SR.Format(SR.DragDrop_DragActionInvalid, "value")
Error message
SR.Format(SR.DragDrop_DragActionInvalid, "value")
What it means
QueryContinueDragEventArgs.Action accepts only values validated by DragDrop.IsValidDragAction: DragAction.Continue, Drop, or Cancel. Setting any other value (e.g. a cast integer or uninitialized enum) throws an ArgumentException with the parameter name 'value'.
Solutions
- Only assign DragAction.Continue, DragAction.Drop, or DragAction.Cancel.
- Validate numeric input with Enum.IsDefined(typeof(DragAction), v) before casting.
- Map native DROPEFFECT constants to the proper DragAction explicitly instead of blind casts.
- Wrap the assignment in validation logic in the drag handler.
Example fix
// before e.Action = (DragAction)nativeEffect; // may be out of range // after e.Action = (nativeEffect & DROPEFFECT_MOVE) != 0 ? DragAction.Drop : DragAction.Continue;
Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(DragAction), value))
throw new ArgumentException($"Invalid DragAction: {value}"); Type guard
static bool IsValidDragAction(DragAction a) =>
a == DragAction.Continue || a == DragAction.Drop || a == DragAction.Cancel; Try / catch
try { args.Action = desiredAction; }
catch (ArgumentException ex) when (ex.Message.Contains("value"))
{ args.Action = DragAction.Cancel; } Prevention
- Never cast raw ints or native DROPEFFECT values directly to DragAction.
- Validate configuration-driven drag behavior with Enum.IsDefined.
- Use only the three documented DragAction members.
When it happens
Trigger: In a QueryContinueDrag handler, assigning e.Action = (DragAction)someInt or an out-of-range value; data-binding or reflection-driven property assignment with invalid enum data.
Common situations: Custom drag controllers storing drag state as int and casting; settings-driven drag behavior where configuration values are not validated; interop code mapping native DROPEFFECT values directly onto DragAction.
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
- ArgumentNullException: handle
- InvalidEnumArgumentException(nameof(format), (int)format…
- SR.DragDrop_DragDropEffectsInvalid
- SR.OleServicesContext_ThreadMustBeSTA
- SR.ScopeMustBeUIElementOrContent
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/28e563d365835e4c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/QueryContinueDragEventArgs.cs:81
{
get {return _dragDropKeyStates;}
}
/// <summary>
/// The action of drag operation
/// </summary>
public DragAction Action
{
get
{
return _action;
}
set
{
if (!DragDrop.IsValidDragAction(value))
{
throw new ArgumentException(SR.Format(SR.DragDrop_DragActionInvalid, "value"));
}
_action = value;
}
}
#endregion Public Methods
#region Protected Methods
//------------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
/// <summary>
/// The mechanism used to call the type-specific handler on the target.View on GitHub (pinned to 81131a70a4)