{"record":{"id":"c44d4a861494e481","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-invokehandler-c44d4a","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'invokeHandler')","messagePattern":"Value cannot be null\\. \\(Parameter 'invokeHandler'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/EventPatternSourceBase.cs","lineNumber":91,"sourceCode":"                    }\n                }\n            }\n        }\n\n        private readonly IObservable<EventPattern<TSender, TEventArgs>> _source;\n        private readonly Dictionary<Delegate, Stack<IDisposable>> _subscriptions = [];\n        private readonly Action<Action<TSender?, TEventArgs>, /*object,*/ EventPattern<TSender, TEventArgs>> _invokeHandler;\n\n        /// <summary>\n        /// Creates a new event pattern source.\n        /// </summary>\n        /// <param name=\"source\">Source sequence to expose as an event.</param>\n        /// <param name=\"invokeHandler\">Delegate used to invoke the event for each element of the sequence.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"invokeHandler\"/> is <c>null</c>.</exception>\n        protected EventPatternSourceBase(IObservable<EventPattern<TSender, TEventArgs>> source, Action<Action<TSender?, TEventArgs>, /*object,*/ EventPattern<TSender, TEventArgs>> invokeHandler)\n        {\n            _source = source ?? throw new ArgumentNullException(nameof(source));\n            _invokeHandler = invokeHandler ?? throw new ArgumentNullException(nameof(invokeHandler));\n        }\n\n        /// <summary>\n        /// Adds the specified event handler, causing a subscription to the underlying source.\n        /// </summary>\n        /// <param name=\"handler\">Event handler to add. The same delegate should be passed to the <see cref=\"Remove(Delegate)\"/> operation in order to remove the event handler.</param>\n        /// <param name=\"invoke\">Invocation delegate to raise the event in the derived class.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"handler\"/> or <paramref name=\"invoke\"/> is <c>null</c>.</exception>\n        protected void Add(Delegate handler, Action<TSender?, TEventArgs> invoke)\n        {\n            if (handler == null)\n            {\n                throw new ArgumentNullException(nameof(handler));\n            }\n\n            if (invoke == null)\n            {\n                throw new ArgumentNullException(nameof(invoke));","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/EventPatternSourceBase.cs#L73-L109","documentation":"The protected EventPatternSourceBase constructor also requires a non-null invokeHandler delegate used to raise the event for each element. Passing null throws ArgumentNullException for 'invokeHandler'.","triggerScenarios":"Subclassing EventPatternSourceBase and passing null as the Action<Action<TSender?,TEventArgs>, EventPattern<TSender,TEventArgs>> invokeHandler argument.","commonSituations":"Custom FromEventPattern-like adapters where the delegate wiring the event raise is conditionally assigned or resolved from a registry that returned null.","solutions":["Supply a valid delegate that invokes the event handler, e.g. (h, e) => handlerTarget?.Invoke(e.Sender, e.EventArgs).","Null-check the delegate before constructing the EventPatternSourceBase."],"exampleFix":"// before\nnew MyEventPatternSource(source, invokeHandler);\n// after\nif (invokeHandler == null) throw new InvalidOperationException(\"invokeHandler not wired\");\nnew MyEventPatternSource(source, invokeHandler);","handlingStrategy":"validation","validationCode":"if (invokeHandler == null) throw new ArgumentNullException(nameof(invokeHandler));","typeGuard":"bool IsValidHandler<TSender, TArgs>(Action<Action<TSender?, TArgs>, EventPattern<TSender, TArgs>>? h) => h is not null;","tryCatchPattern":"try { new MyEventPatternSource(source, invokeHandler); } catch (ArgumentNullException ex) when (ex.ParamName == \"invokeHandler\") { /* wire the raise delegate */ }","preventionTips":["Define the event-raise lambda inline where the base constructor is called.","Never resolve invoke handlers from registries that can return null without checking."],"tags":["argument-null","event-pattern","constructor"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}