{"record":{"id":"d0a9a19656c8cae6","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-source","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(source));","messagePattern":"throw new ArgumentNullException\\(nameof\\(source\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":284,"sourceCode":"\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, ValueTask<IAsyncObservable<TResult>>> selector, TimeSpan window, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, () => new ValueTask<IAsyncSubject<TSource, TSource>>(new SequentialReplayAsyncSubject<TSource>(window, scheduler)), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, ValueTask<IAsyncObservable<TResult>>> selector, int bufferSize, TimeSpan window)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n            if (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n\n            return Multicast(source, () => new ValueTask<IAsyncSubject<TSource, TSource>>(new SequentialReplayAsyncSubject<TSource>(bufferSize, window)), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, ValueTask<IAsyncObservable<TResult>>> selector, int bufferSize, TimeSpan window, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (selector == null)\n                throw new ArgumentNullException(nameof(selector));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L266-L302","documentation":"The Replay(source, selector, bufferSize, window) overload throws ArgumentNullException when the source observable is null. The library validates each argument in order before building the multicast replay subject. A null source cannot be replayed.","triggerScenarios":"Calling source.Replay(selector, bufferSize, window) where the IAsyncObservable<TSource> argument is null; note bufferSize >= 0 and window >= 0 are checked afterwards, so the null-source error fires first.","commonSituations":"Chaining Replay onto a method that returned null; uninitialized stream fields; race where the source is assigned after the pipeline is built.","solutions":["Initialize the source observable before composing the pipeline.","Return an empty observable from factories instead of null.","Defer pipeline construction until the source is available."],"exampleFix":"// before\nvar result = LoadSource().Replay(sel, 10, TimeSpan.FromSeconds(5)); // LoadSource() returned null\n// after\nvar src = LoadSource() ?? AsyncObservable.Empty<int>();\nvar result = src.Replay(sel, 10, TimeSpan.FromSeconds(5));","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"source observable is not initialized\");","typeGuard":"bool IsValidSource<TSource>(IAsyncObservable<TSource> s) => s != null;","tryCatchPattern":"try { var r = source.Replay(sel, bufferSize, window); } catch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* handle missing source */ }","preventionTips":["Never chain operators on methods that can return null","Initialize observable fields eagerly","Use nullable reference types to surface null sources at compile time"],"tags":["argument-null","source-observable","async-rx","replay-operator"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}