{"record":{"id":"64745f1cad9e4722","repo":"PrismLibrary/Prism","slug":"argumentnullexception-nameof-eventsubscription","errorCode":null,"errorMessage":"ArgumentNullException(nameof(eventSubscription))","messagePattern":"ArgumentNullException\\(nameof\\(eventSubscription\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventBase.cs","lineNumber":39,"sourceCode":"        /// Gets the list of current subscriptions.\n        /// </summary>\n        /// <value>The current subscribers.</value>\n        protected ICollection<IEventSubscription> Subscriptions\n        {\n            get { return _subscriptions; }\n        }\n\n        /// <summary>\n        /// Adds the specified <see cref=\"IEventSubscription\"/> to the subscribers' collection.\n        /// </summary>\n        /// <param name=\"eventSubscription\">The subscriber.</param>\n        /// <returns>The <see cref=\"SubscriptionToken\"/> that uniquely identifies every subscriber.</returns>\n        /// <remarks>\n        /// Adds the subscription to the internal list and assigns it a new <see cref=\"SubscriptionToken\"/>.\n        /// </remarks>\n        protected virtual SubscriptionToken InternalSubscribe(IEventSubscription eventSubscription)\n        {\n            if (eventSubscription == null) throw new ArgumentNullException(nameof(eventSubscription));\n\n            eventSubscription.SubscriptionToken = new SubscriptionToken(Unsubscribe);\n\n            lock (Subscriptions)\n            {\n                Subscriptions.Add(eventSubscription);\n            }\n            return eventSubscription.SubscriptionToken;\n        }\n\n        /// <summary>\n        /// Calls all the execution strategies exposed by the list of <see cref=\"IEventSubscription\"/>.\n        /// </summary>\n        /// <param name=\"arguments\">The arguments that will be passed to the listeners.</param>\n        /// <remarks>Before executing the strategies, this class will prune all the subscribers from the\n        /// list that return a <see langword=\"null\" /> <see cref=\"Action{T}\"/> when calling the\n        /// <see cref=\"IEventSubscription.GetExecutionStrategy\"/> method.</remarks>\n        protected virtual void InternalPublish(params object[] arguments)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventBase.cs#L21-L57","documentation":"EventBase.InternalSubscribe adds an IEventSubscription to the event's subscription list and assigns it a token. It throws ArgumentNullException when the supplied eventSubscription is null because a null subscription cannot be tracked or later unsubscribed.","triggerScenarios":"Overriding PubSubEvent/EventBase and calling InternalSubscribe(null), or custom IEventSubscription factories returning null which is then passed straight to InternalSubscribe.","commonSituations":"Custom event subclasses in Prism where the execution-strategy/subscription construction was refactored and now returns null; test doubles of EventBase.","solutions":["Ensure the subscription object is fully constructed before calling InternalSubscribe","Check factory results for null before subscribing","If overriding, add your own null guard and fail early with a clear message"],"exampleFix":"// before\nvar sub = BuildSubscription(); // may return null\nInternalSubscribe(sub);\n// after\nvar sub = BuildSubscription() ?? throw new InvalidOperationException(\"subscription factory returned null\");\nInternalSubscribe(sub);","handlingStrategy":"type-guard","validationCode":"if (subscription == null) throw new InvalidOperationException(\"Subscription factory returned null\");","typeGuard":"bool CanSubscribe(IEventSubscription s) => s != null;","tryCatchPattern":"try { InternalSubscribe(sub); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"eventSubscription\") { log.Error(\"Null subscription passed to InternalSubscribe\"); }","preventionTips":["Only call InternalSubscribe from within well-tested PubSubEvent base flow","Null-check results of subscription factories in custom event subclasses"],"tags":["prism","eventaggregator","argumentnull","subscription"],"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"}