{"record":{"id":"d18083feb4dd7237","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-scheduler-replay","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'scheduler')","messagePattern":"Value cannot be null\\. \\(Parameter 'scheduler'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs","lineNumber":28,"sourceCode":"{\n    // REVIEW: Expose Replay using ConcurrentAsyncAsyncSubject<T> underneath.\n\n    public partial class AsyncObservable\n    {\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>());\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(scheduler));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (bufferSize < 0)\n                throw new ArgumentOutOfRangeException(nameof(bufferSize));\n\n            return Multicast(source, new SequentialReplayAsyncSubject<TSource>(bufferSize));\n        }\n\n        public static IConnectableAsyncObservable<TSource> Replay<TSource>(this IAsyncObservable<TSource> source, int bufferSize, IAsyncScheduler scheduler)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Replay.cs#L10-L46","documentation":"Replay(source, scheduler) throws ArgumentNullException('scheduler') when the scheduler argument is null. A scheduler is required for this overload because the replay subject (SequentialReplayAsyncSubject) uses it for time-based behavior; the library does not default to a standard scheduler implicitly here.","triggerScenarios":"Calling source.Replay(scheduler) with scheduler == null, e.g. an optional scheduler field that defaulted to null, or a DI container that failed to resolve the scheduler.","commonSituations":"DI misconfiguration where IAsyncScheduler isn't registered; passing a TaskPool/Default scheduler variable that was never initialized; test setups that forgot to supply a test scheduler.","solutions":["Pass an explicit scheduler, e.g. use the library's default/timeout scheduler singleton or your configured IAsyncScheduler.","If you don't need custom scheduling, call the parameterless source.Replay() overload instead.","Fix DI registration so an IAsyncScheduler is available at the call site."],"exampleFix":"// before\nIAsyncScheduler sched = null;\nvar replay = source.Replay(sched); // throws\n// after\nvar replay = source.Replay(new DefaultAsyncScheduler()); // or source.Replay()","handlingStrategy":"validation","validationCode":"if (scheduler == null)\n    scheduler = new DefaultAsyncScheduler(); // or your configured IAsyncScheduler\nvar replay = source.Replay(scheduler);","typeGuard":"static bool HasScheduler(IAsyncScheduler? scheduler) => scheduler is not null;","tryCatchPattern":"try\n{\n    var replay = source.Replay(scheduler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"scheduler\")\n{\n    var replay = source.Replay(); // fall back to parameterless overload\n}","preventionTips":["Default schedulers at composition time, never pass raw nullable scheduler fields.","Register IAsyncScheduler in DI and require it in constructors.","Use the parameterless Replay() when you do not need scheduler control."],"tags":["null-argument","rx","scheduler","argument-validation"],"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"}