{"record":{"id":"1c20cf4896712a77","repo":"PrismLibrary/Prism","slug":"argumentnullexception-nameof-action","errorCode":null,"errorMessage":"ArgumentNullException(nameof(action))","messagePattern":"ArgumentNullException\\(nameof\\(action\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventSubscription.cs","lineNumber":79,"sourceCode":"            Action action = this.Action;\n            if (action != null)\n            {\n                return arguments =>\n                {\n                    InvokeAction(action);\n                };\n            }\n            return null;\n        }\n\n        /// <summary>\n        /// Invokes the specified <see cref=\"System.Action{TPayload}\"/> synchronously when not overridden.\n        /// </summary>\n        /// <param name=\"action\">The action to execute.</param>\n        /// <exception cref=\"ArgumentNullException\">An <see cref=\"ArgumentNullException\"/> is thrown if <paramref name=\"action\"/> is null.</exception>\n        protected virtual void InvokeAction(Action action)\n        {\n            if (action == null) throw new ArgumentNullException(nameof(action));\n\n            action();\n        }\n    }\n\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    /// <typeparam name=\"TPayload\">The type to use for the generic <see cref=\"System.Action{TPayload}\"/> and <see cref=\"Predicate{TPayload}\"/> types.</typeparam>\n    public class EventSubscription<TPayload> : IEventSubscription\n    {\n        private readonly IDelegateReference _actionReference;\n        private readonly IDelegateReference _filterReference;\n\n        ///<summary>\n        /// Creates a new instance of <see cref=\"EventSubscription{TPayload}\"/>.\n        ///</summary>","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventSubscription.cs#L61-L97","documentation":"EventSubscription<TPayload>.InvokeAction executes the subscription's Action synchronously. It throws ArgumentNullException when the action parameter is null, which protects the publish pipeline from executing a null callback.","triggerScenarios":"GetExecutionStrategy resolving a strategy whose action comes from a DelegateReference whose Target was garbage collected (weak reference) or is null, then publishing the event; overriding InvokeAction and calling it with null.","commonSituations":"Weak (keepReferenceAlive:false) subscriptions where the subscriber was collected before publish, so the action can no longer be resolved.","solutions":["Keep the subscriber alive or pass keepReferenceAlive:true to Subscribe","Unsubscribe when the subscriber is disposed so dead subscriptions are removed","If overriding InvokeAction, never call it with a null action"],"exampleFix":"// before\n_event.Subscribe(Handler); // Handler in short-lived object, weak ref dies\n// after\n_event.Subscribe(Handler, keepReferenceAlive: true);\n// or unsubscribe on dispose: _event.Unsubscribe(token);","handlingStrategy":"try-catch","validationCode":"var strategy = subscription.GetExecutionStrategy();\nif (strategy == null) return; // dead/collected subscription","typeGuard":null,"tryCatchPattern":"try { strategy(); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"action\") { log.Warn(\"Subscription action no longer available (weak reference collected)\"); _event.Unsubscribe(token); }","preventionTips":["Unsubscribe on subscriber disposal instead of relying on weak references","Use keepReferenceAlive:true for long-lived publishers with short-lived subscribers","Publish only to subscriptions verified alive"],"tags":["prism","eventaggregator","argumentnull","weak-reference"],"backgroundTag":"null-argument","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"}