{"record":{"id":"c627e7efdf9cf015","repo":"lucasg/Dependencies","slug":"execute","errorCode":null,"errorMessage":"execute","messagePattern":"execute","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"DependenciesGui/Helpers/RelayCommand.cs","lineNumber":19,"sourceCode":"﻿using System;\nusing System.Windows.Input;\nusing System.Diagnostics;\n\nnamespace Dependencies\n{\n    public class RelayCommand : ICommand\n    {\n        #region Fields \n        readonly Action<object> _execute;\n        readonly Predicate<object> _canExecute;\n        #endregion // Fields \n\n        #region Constructors \n        public RelayCommand(Action<object> execute) : this(execute, null) { }\n        public RelayCommand(Action<object> execute, Predicate<object> canExecute)\n        {\n            if (execute == null)\n                throw new ArgumentNullException(\"execute\");\n            _execute = execute; _canExecute = canExecute;\n        }\n        #endregion // Constructors \n\n        #region ICommand Members \n        [DebuggerStepThrough]\n        public bool CanExecute(object parameter)\n        {\n            return _canExecute == null ? true : _canExecute(parameter);\n        }\n        public event EventHandler CanExecuteChanged\n        {\n            add { CommandManager.RequerySuggested += value; }\n            remove { CommandManager.RequerySuggested -= value; }\n        }\n        public void Execute(object parameter) { _execute(parameter); }\n        #endregion // ICommand Members \n    }","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/lucasg/Dependencies/blob/1997a40000b77bd3326cbc33672a7b9f78bb23f3/DependenciesGui/Helpers/RelayCommand.cs#L1-L37","documentation":"ArgumentNullException thrown by the RelayCommand constructor (param name \"execute\"). RelayCommand is the standard MVVM ICommand implementation used across Dependencies; it stores an Action<object> to run on Execute and an optional Predicate<object> for CanExecute. Constructing it with a null execute delegate violates the command contract, so the constructor fails fast at creation time rather than producing a NullReferenceException later when Execute is invoked.","triggerScenarios":"Writing `new RelayCommand(null)` or `new RelayCommand(null, canExecute)` - i.e. the first constructor argument evaluates to null at the moment the command object is created.","commonSituations":"A refactor removes the action lambda but leaves the `new RelayCommand(...)` call; a method-group/lambda that conditionally resolves to null; a binding/converter yields null that is passed into the constructor; copy-paste of a command definition without the body.","solutions":["Pass a non-null Action<object> lambda, e.g. `new RelayCommand(_ => Open())`.","If the command is genuinely unused, remove the property/field and its XAML binding instead of passing null.","If the action is optional, guard the caller and skip constructing the command when it is null.","Add a unit test that constructs each command to catch the regression at build time."],"exampleFix":"// before\n_OpenNewAppCommand = new RelayCommand(null);\n\n// after\n_OpenNewAppCommand = new RelayCommand(_ => OpenNewApp());","handlingStrategy":"validation","validationCode":"Action<object> action = ResolveAction();\nif (action == null) return null; // or throw a clearer domain error\nICommand cmd = new RelayCommand(action);","typeGuard":"static bool IsValidCommand(Action<object> execute)\n{\n    return execute != null;\n}","tryCatchPattern":null,"preventionTips":["Never pass a literal null as the first RelayCommand argument.","After refactoring a command, build and run a quick constructor unit test.","Prefer expression-body lambdas so a missing body is a compile error, not a silent null."],"tags":["mvvm","icommand","relaycommand","argumentnull","constructor"],"backgroundTag":null,"analyzedSha":"1997a40000b77bd3326cbc33672a7b9f78bb23f3","analyzedAt":"2026-08-13T18:14:41.696Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}