{"record":{"id":"46be15831fec57b1","repo":"dotnet/reactive","slug":"argumentnullexception-scheduler","errorCode":null,"errorMessage":"ArgumentNullException: scheduler","messagePattern":"ArgumentNullException: scheduler","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":450,"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        /// <param name=\"source\">Source sequence whose elements will be multicasted through a single shared subscription.</param>\n        /// <param name=\"scheduler\">Scheduler where connected observers will be invoked on.</param>\n        /// <returns>A connectable observable sequence that shares a single subscription to the underlying sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <remarks>Subscribers will receive all the notifications of the source.</remarks>\n        /// <seealso cref=\"ReplaySubject{T}\"/>\n        public static IConnectableObservable<TSource> Replay<TSource>(this IObservable<TSource> source, IScheduler scheduler)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Replay(source, scheduler);\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        /// <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        {","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L432-L468","documentation":"Observable.Replay(source, scheduler) throws ArgumentNullException with ParamName \"scheduler\" when the IScheduler argument is null (source already validated non-null). Replay with a scheduler needs a valid scheduler to timestamp/serialize replays.","triggerScenarios":"Calling source.Replay(null) or passing a scheduler variable that was never initialized, e.g. Replay(source, defaultScheduler) where defaultScheduler is null.","commonSituations":"Config-based scheduler selection falling through to null, or passing Scheduler.Default typed as null in generic code.","solutions":["Pass a concrete IScheduler such as Scheduler.Default, Scheduler.Immediate, or TaskPoolScheduler.Default.","Fix the config/branch that resolved the scheduler to null.","Guard the call: if (scheduler == null) scheduler = Scheduler.Default;"],"exampleFix":"// before\nvar conn = source.Replay(null);\n// after\nvar conn = source.Replay(Scheduler.Default);","handlingStrategy":"validation","validationCode":"scheduler ??= Scheduler.Default; // before calling Replay","typeGuard":"static IScheduler NonNull(IScheduler? s) => s ?? Scheduler.Default;","tryCatchPattern":"try { var conn = source.Replay(scheduler); } catch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\") { scheduler = Scheduler.Default; }","preventionTips":["Always use concrete schedulers (Scheduler.Default, NewThreadScheduler.Default) rather than possibly-null fields.","Centralize scheduler resolution in one non-null-returning helper.","Validate config-driven scheduler names resolve to a type at startup."],"tags":["null-argument","reactive","scheduler"],"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"}