{"record":{"id":"1bb6214175710b62","repo":"PrismLibrary/Prism","slug":"argumentnullexception-nameof-actionreference","errorCode":null,"errorMessage":"ArgumentNullException(nameof(actionReference))","messagePattern":"ArgumentNullException\\(nameof\\(actionReference\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventSubscription.cs","lineNumber":24,"sourceCode":"{\n    /// <summary>\n    /// Provides a way to retrieve a <see cref=\"Delegate\"/> to execute an action depending\n    /// on the value of a second filter predicate that returns true if the action should execute.\n    /// </summary>\n    public class EventSubscription : IEventSubscription\n    {\n        private readonly IDelegateReference _actionReference;\n\n        ///<summary>\n        /// Creates a new instance of <see cref=\"EventSubscription\"/>.\n        ///</summary>\n        ///<param name=\"actionReference\">A reference to a delegate of type <see cref=\"System.Action\"/>.</param>\n        ///<exception cref=\"ArgumentNullException\">When <paramref name=\"actionReference\"/> or <see paramref=\"filterReference\"/> are <see langword=\"null\" />.</exception>\n        ///<exception cref=\"ArgumentException\">When the target of <paramref name=\"actionReference\"/> is not of type <see cref=\"System.Action\"/>.</exception>\n        public EventSubscription(IDelegateReference actionReference)\n        {\n            if (actionReference == null)\n                throw new ArgumentNullException(nameof(actionReference));\n            if (!(actionReference.Target is Action))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action).FullName), nameof(actionReference));\n\n            _actionReference = actionReference;\n        }\n\n        /// <summary>\n        /// Gets the target <see cref=\"System.Action\"/> that is referenced by the <see cref=\"IDelegateReference\"/>.\n        /// </summary>\n        /// <value>An <see cref=\"System.Action\"/> or <see langword=\"null\" /> if the referenced target is not alive.</value>\n        public Action Action\n        {\n            get { return (Action)_actionReference.Target; }\n        }\n\n        /// <summary>\n        /// Gets or sets a <see cref=\"SubscriptionToken\"/> that identifies this <see cref=\"IEventSubscription\"/>.\n        /// </summary>","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventSubscription.cs#L6-L42","documentation":"The non-generic EventSubscription constructor stores an IDelegateReference that must wrap a System.Action. It throws ArgumentNullException when actionReference is null and ArgumentException (Resources.InvalidDelegateRerefenceTypeException) when the reference's Target is not an Action.","triggerScenarios":"new EventSubscription(null); or new EventSubscription(new DelegateReference(someFuncOrNonActionDelegate, false)) where the wrapped target is a Func, Predicate, or custom delegate rather than Action.","commonSituations":"Building custom PubSubEvent subscription internals; passing a DelegateReference created for a differently-typed delegate after refactoring the event payload/signature.","solutions":["Pass a DelegateReference whose Target is a System.Action","Verify the delegate type before creating the DelegateReference","Use the public PubSubEvent.Subscribe API instead of constructing EventSubscription manually"],"exampleFix":"// before\nvar sub = new EventSubscription(new DelegateReference((Func<int>)() => 1, false));\n// after\nvar sub = new EventSubscription(new DelegateReference((Action)(() => { }), false));","handlingStrategy":"validation","validationCode":"if (actionReference?.Target is Action) { var sub = new EventSubscription(actionReference); }","typeGuard":"bool IsValidActionRef(IDelegateReference r) => r?.Target is Action;","tryCatchPattern":"try { var sub = new EventSubscription(actionRef); }\ncatch (ArgumentException ex) { log.Error($\"actionReference target must be Action: {ex.Message}\"); }\ncatch (ArgumentNullException) { log.Error(\"actionReference was null\"); }","preventionTips":["Wrap parameterless System.Action delegates only","Prefer the public Subscribe API over manual EventSubscription construction"],"tags":["prism","eventaggregator","type-mismatch","argumentnull","delegate"],"backgroundTag":"type-mismatch","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}