{"record":{"id":"2f8f38dd0022dd64","repo":"dotnet/reactive","slug":"argumentnullexception-source-observable-binding","errorCode":null,"errorMessage":"ArgumentNullException: source","messagePattern":"ArgumentNullException: source","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs","lineNumber":445,"sourceCode":"            return s_impl.Replay(source);\n        }\n\n        /// <summary>\n        /// Returns 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        /// <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>","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Binding.cs#L427-L463","documentation":"Observable.Replay(source, scheduler) throws ArgumentNullException with ParamName \"source\" when the source IObservable is null. This overload takes both a source and an IScheduler; the source null-check happens first (line ~445), before the scheduler check. Rx throws eagerly at argument-validation time.","triggerScenarios":"Calling Replay(null, scheduler), or chaining .Replay(scheduler) on a null IObservable reference.","commonSituations":"Constructing replay pipelines from configurable sources where a config-driven lookup returned null; test harnesses passing null sources.","solutions":["Supply a non-null IObservable<TSource> as the first argument.","Fix the code that produced the null source (factory, DI, config lookup).","Add a pre-call null guard so the failure surfaces at the right place."],"exampleFix":"// before\nobs.Replay(scheduler); // obs is null\n// after\nvar obs = obs ?? Observable.Empty<int>();\nobs.Replay(scheduler);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"Replay(source, scheduler) requires a non-null source.\");","typeGuard":"static bool CanReplayOn<T>(IObservable<T>? s, IScheduler sch) => s is not null && sch is not null;","tryCatchPattern":"try { var conn = source.Replay(scheduler); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* handle */ }","preventionTips":["Check argument order: source first, scheduler second.","Initialize observable fields before scheduled replay setup runs.","Use nullable annotations on factory return types to catch nulls early."],"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"}