{"record":{"id":"f4ce784b31fd41bc","repo":"PrismLibrary/Prism","slug":"argumentnullexception-nameof-filterreference","errorCode":null,"errorMessage":"ArgumentNullException(nameof(filterReference))","messagePattern":"ArgumentNullException\\(nameof\\(filterReference\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Prism.Events/EventSubscription.cs","lineNumber":111,"sourceCode":"        private readonly IDelegateReference _filterReference;\n\n        ///<summary>\n        /// Creates a new instance of <see cref=\"EventSubscription{TPayload}\"/>.\n        ///</summary>\n        ///<param name=\"actionReference\">A reference to a delegate of type <see cref=\"System.Action{TPayload}\"/>.</param>\n        ///<param name=\"filterReference\">A reference to a delegate of type <see cref=\"Predicate{TPayload}\"/>.</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{TPayload}\"/>,\n        ///or the target of <paramref name=\"filterReference\"/> is not of type <see cref=\"Predicate{TPayload}\"/>.</exception>\n        public EventSubscription(IDelegateReference actionReference, IDelegateReference filterReference)\n        {\n            if (actionReference == null)\n                throw new ArgumentNullException(nameof(actionReference));\n            if (!(actionReference.Target is Action<TPayload>))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Action<TPayload>).FullName), nameof(actionReference));\n\n            if (filterReference == null)\n                throw new ArgumentNullException(nameof(filterReference));\n            if (!(filterReference.Target is Predicate<TPayload>))\n                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidDelegateRerefenceTypeException, typeof(Predicate<TPayload>).FullName), nameof(filterReference));\n\n            _actionReference = actionReference;\n            _filterReference = filterReference;\n        }\n\n        /// <summary>\n        /// Gets the target <see cref=\"System.Action{T}\"/> that is referenced by the <see cref=\"IDelegateReference\"/>.\n        /// </summary>\n        /// <value>An <see cref=\"System.Action{T}\"/> or <see langword=\"null\" /> if the referenced target is not alive.</value>\n        public Action<TPayload> Action\n        {\n            get { return (Action<TPayload>)_actionReference.Target; }\n        }\n\n        /// <summary>\n        /// Gets the target <see cref=\"Predicate{T}\"/> that is referenced by the <see cref=\"IDelegateReference\"/>.","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Prism.Events/EventSubscription.cs#L93-L129","documentation":"EventSubscription's constructor requires a non-null filterReference wrapping a Predicate<TPayload>. Prism throws ArgumentNullException when the filter reference itself is null, because a subscription without a filter cannot decide which published payloads to deliver.","triggerScenarios":"Calling new EventSubscription<TPayload>(actionReference, null), or calling PubSubEvent.Subscribe with a null filter delegate that ends up wrapped in a null IDelegateReference.","commonSituations":"Passing a null filter variable (e.g. a field not yet initialized), or custom subscription wiring code that forgets to supply the filter when Prism's default filter (always true) was expected.","solutions":["Pass a valid filter delegate reference, e.g. a Predicate<TPayload> wrapping 'return true;' for accept-all behavior","Ensure the variable holding the filter is initialized before constructing the subscription","If no filtering is needed, call the Subscribe overload without the filter parameter instead of passing null"],"exampleFix":"// before\nvar sub = new EventSubscription<string>(actionRef, null);\n// after\nvar sub = new EventSubscription<string>(actionRef, new DelegateReference((Predicate<string>)(p => true), false));","handlingStrategy":"validation","validationCode":"if (filterReference == null)\n    throw new ArgumentNullException(nameof(filterReference));\nif (filterReference?.Target is not Predicate<TPayload>)\n    throw new ArgumentException(\"filter must be a Predicate<TPayload>\", nameof(filterReference));","typeGuard":"bool IsValidFilter<TPayload>(IDelegateReference r) => r?.Target is Predicate<TPayload>;","tryCatchPattern":null,"preventionTips":["Never pass null for the filter; use p => true for accept-all","Prefer the PubSubEvent.Subscribe overloads over constructing EventSubscription directly","Initialize filter fields before constructing subscriptions"],"tags":["prism","events","null-argument"],"backgroundTag":"null-argument","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}