{"record":{"id":"28e563d365835e4c","repo":"dotnet/wpf","slug":"sr-format-sr-dragdrop-dragactioninvalid-value","errorCode":null,"errorMessage":"SR.Format(SR.DragDrop_DragActionInvalid, \"value\")","messagePattern":"SR\\.Format\\(SR\\.DragDrop_DragActionInvalid, \"value\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/QueryContinueDragEventArgs.cs","lineNumber":81,"sourceCode":"        {\n            get {return _dragDropKeyStates;}\n        }\n\n        /// <summary>\n        /// The action of drag operation\n        /// </summary>\n        public DragAction Action\n        {\n            get \n            {   \n                return _action;\n            }\n\n            set \n            {\n                if (!DragDrop.IsValidDragAction(value))\n                {\n                    throw new ArgumentException(SR.Format(SR.DragDrop_DragActionInvalid, \"value\"));\n                }\n\n                _action = value; \n            }\n        }\n\n        #endregion Public Methods\n\n        #region Protected Methods\n\n        //------------------------------------------------------\n        //\n        //  Protected Methods\n        //\n        //------------------------------------------------------\n\n        /// <summary>\n        /// The mechanism used to call the type-specific handler on the target.","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/QueryContinueDragEventArgs.cs#L63-L99","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ne.Action = (DragAction)nativeEffect; // may be out of range\n\n// after\ne.Action = (nativeEffect & DROPEFFECT_MOVE) != 0 ? DragAction.Drop : DragAction.Continue;","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(DragAction), value))\n    throw new ArgumentException($\"Invalid DragAction: {value}\");","typeGuard":"static bool IsValidDragAction(DragAction a) =>\n    a == DragAction.Continue || a == DragAction.Drop || a == DragAction.Cancel;","tryCatchPattern":"try { args.Action = desiredAction; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"value\"))\n{ args.Action = DragAction.Cancel; }","preventionTips":["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."],"tags":["wpf","drag-drop","enum-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"}