{"record":{"id":"795b2842ccd13fa0","repo":"dotnet/reactive","slug":"selector","errorCode":null,"errorMessage":"selector","messagePattern":"selector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":142,"sourceCode":"\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector, int bufferSize)\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\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(bufferSize), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector, int bufferSize, 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));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(bufferSize, scheduler), selector);\n        }\n\n        public static IAsyncObservable<TResult> Replay<TSource, TResult>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> selector, 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 (window < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(window));\n\n            return Multicast(source, () => new SequentialReplayAsyncSubject<TSource>(window), selector);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L124-L160","documentation":"The Replay(source, selector, bufferSize, scheduler) overload throws ArgumentNullException because the selector delegate passed was null. The operator needs a non-null selector to build the multicast pipeline over the replay subject; a null selector would make the returned observable impossible to construct. The library validates all arguments eagerly at call time so failures surface at the call site rather than later during subscription.","triggerScenarios":"Calling source.Replay(null, bufferSize, scheduler) or passing a variable/ternary/expression that evaluates to a null Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>>.","commonSituations":"Building the selector dynamically (e.g. from configuration or a dictionary of transforms) and the lookup fails returning null; refactoring code where the selector lambda was accidentally deleted; conditional pipelines that pass null when a feature flag is off.","solutions":["Pass a non-null selector lambda, e.g. src => src.Select(...).Where(...).","If the selector is variable, check it for null before calling Replay and handle the fallback explicitly.","Verify the variable actually holds the composed delegate and was not reassigned to null elsewhere."],"exampleFix":"// before\nIAsyncObservable<int> result = source.Replay(null, 10, Scheduler.Default.Async);\n// after\nIAsyncObservable<int> result = source.Replay(xs => xs.Select(x => x * 2), 10, Scheduler.Default.Async);","handlingStrategy":"validation","validationCode":"if (selector is null) throw new InvalidOperationException(\"Replay selector must be provided\");\n// safe to call source.Replay(selector, bufferSize, scheduler);","typeGuard":"bool HasSelector(Func<IAsyncObservable<TSource>, IAsyncObservable<TResult>> f) => f is not null;","tryCatchPattern":"try { var r = source.Replay(selector, bufferSize, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"selector\") { /* supply a default selector or fail fast */ }","preventionTips":["Always pass a lambda literal where possible instead of nullable delegate variables.","Validate delegates at pipeline-configuration time, before building operators.","Use required constructor/injection parameters for selectors."],"tags":["argument-null","replay","async-reactive"],"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"}