{"record":{"id":"b851d6d1df493504","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-selector-observable-binding","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'selector')","messagePattern":"Value cannot be null\\. \\(Parameter 'selector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":917,"sourceCode":"        /// <param name=\"selector\">Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.</param>\n        /// <param name=\"bufferSize\">Maximum element count of the replay buffer.</param>\n        /// <param name=\"window\">Maximum time length of the replay buffer.</param>\n        /// <param name=\"scheduler\">Scheduler where connected observers within the selector function will be invoked on.</param>\n        /// <returns>An observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a selector function.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"selector\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"bufferSize\"/> is less than zero.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"window\"/> is less than TimeSpan.Zero.</exception>\n        /// <seealso cref=\"ReplaySubject{T}\"/>\n        public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, int bufferSize, TimeSpan window, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (selector == null)\n            {\n                throw new ArgumentNullException(nameof(selector));\n            }\n\n            if (bufferSize < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n            }\n\n            if (window < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(window));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Replay(source, selector, bufferSize, window, scheduler);","sourceCodeStart":899,"sourceCodeEnd":935,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L899-L935","documentation":"In Replay(source, selector, bufferSize, window, scheduler) the selector function that receives the replayed view of the source is required and must not be null. Null is rejected eagerly with ArgumentNullException (parameter 'selector').","triggerScenarios":"Calling source.Replay(null, bufferSize, window, scheduler); typically a lambda variable that is null because it was stored in a field/delegate and never assigned, or an accidental null literal.","commonSituations":"Storing query lambdas in injectable strategy objects that default to null; conditional code paths that skip selector assignment; passing a Func variable that a factory returned as null.","solutions":["Pass an explicit lambda to the selector parameter","Initialize the delegate/strategy before use","Use the non-selector Replay overload if windowing the whole source is sufficient"],"exampleFix":"// before\nFunc<IObservable<int>, IObservable<int>> sel = null;\nvar replayed = source.Replay(sel, 10, TimeSpan.FromSeconds(5), Scheduler.Default);\n// after\nvar replayed = source.Replay(w => w.Select(x => x * 2), 10, TimeSpan.FromSeconds(5), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (selector is null) throw new InvalidOperationException(\"A selector function is required for Replay with selector\");","typeGuard":"static bool IsValidSelector<TSource, TResult>(Func<IObservable<TSource>, IObservable<TResult>> selector) => selector is not null;","tryCatchPattern":"try { var r = src.Replay(selector, size, window, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { /* use identity selector: w => w */ }","preventionTips":["Always pass an inline lambda rather than a possibly-null delegate field","Initialize strategy delegates at construction","Use the non-selector overload when no projection is needed"],"tags":["csharp","rx","null-argument","delegate"],"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"}