{"record":{"id":"250252be50fd1d08","repo":"dotnet/reactive","slug":"argumentnullexception-selector","errorCode":null,"errorMessage":"ArgumentNullException: selector","messagePattern":"ArgumentNullException: selector","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":476,"sourceCode":"        /// This operator is a specialization of Multicast using a <see cref=\"ReplaySubject{T}\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence whose elements will be multicasted through a single shared subscription.</param>\n        /// <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.</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\"/> is null.</exception>\n        /// <seealso cref=\"ReplaySubject{T}\"/>\n        public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector)\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            return s_impl.Replay(source, selector);\n        }\n\n        /// <summary>\n        /// Returns an observable sequence that is the result of invoking the selector on a connectable observable sequence that shares a single subscription to the underlying sequence replaying all notifications.\n        /// This operator is a specialization of Multicast using a <see cref=\"ReplaySubject{T}\"/>.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <typeparam name=\"TResult\">The type of the elements in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence whose elements will be multicasted through a single shared subscription.</param>\n        /// <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.</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        /// <seealso cref=\"ReplaySubject{T}\"/>\n        public static IObservable<TResult> Replay<TSource, TResult>(this IObservable<TSource> source, Func<IObservable<TSource>, IObservable<TResult>> selector, IScheduler scheduler)","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L458-L494","documentation":"Observable.Replay(source, selector) throws ArgumentNullException with ParamName \"selector\" when the Func<IObservable<TSource>, IObservable<TResult>> argument is null (source already checked). The selector defines the multicast projection and is required.","triggerScenarios":"Calling source.Replay(null) where the intent was the parameterless/scheduler overload but a null Func was passed, or a selector delegate variable left unassigned.","commonSituations":"Conditional selector construction that fell through to null; passing a method group that failed to resolve and was silently null in dynamic/reflection-based code.","solutions":["Pass a valid selector lambda, e.g. source.Replay(xs => xs.Take(5)).","If you did not want projection, use the parameterless source.Replay() overload instead.","Fix the variable/branch that produced a null Func."],"exampleFix":"// before\nFunc<IObservable<int>, IObservable<int>>? sel = PickSelector(); // null\nvar q = source.Replay(sel);\n// after\nvar q = source.Replay(xs => xs.Take(5));","handlingStrategy":"validation","validationCode":"if (selector == null) throw new InvalidOperationException(\"Replay selector delegate is required.\");","typeGuard":"static bool HasSelector<T, R>(Func<IObservable<T>, IObservable<R>>? sel) => sel is not null;","tryCatchPattern":"try { var q = source.Replay(selector); } catch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { var conn = source.Replay(); /* fallback: no projection */ }","preventionTips":["If no projection is needed, call the parameterless Replay() overload instead of passing null.","Build selectors with lambdas at the call site to avoid null delegate variables.","Check you did not accidentally pass null where a Func was expected."],"tags":["null-argument","reactive","selector"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}