{"record":{"id":"a1b2359a2fd156f0","repo":"dotnet/reactive","slug":"new-argumentnullexception-nameof-timeselector","errorCode":null,"errorMessage":"new ArgumentNullException(nameof(timeSelector))","messagePattern":"new ArgumentNullException\\(nameof\\(timeSelector\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs","lineNumber":356,"sourceCode":"                throw new ArgumentNullException(nameof(resultSelector));\n            if (timeSelector == null)\n                throw new ArgumentNullException(nameof(timeSelector));\n\n            return Generate(observer, initialState, condition, iterate, resultSelector, timeSelector, TaskPoolAsyncScheduler.Default);\n        }\n\n        public static ValueTask<IAsyncDisposable> Generate<TState, TResult>(IAsyncObserver<TResult> observer, TState initialState, Func<TState, ValueTask<bool>> condition, Func<TState, ValueTask<TState>> iterate, Func<TState, ValueTask<TResult>> resultSelector, Func<TState, ValueTask<TimeSpan>> timeSelector, IAsyncScheduler scheduler)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (condition == null)\n                throw new ArgumentNullException(nameof(condition));\n            if (iterate == null)\n                throw new ArgumentNullException(nameof(iterate));\n            if (resultSelector == null)\n                throw new ArgumentNullException(nameof(resultSelector));\n            if (timeSelector == null)\n                throw new ArgumentNullException(nameof(timeSelector));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return scheduler.ScheduleAsync(async ct =>\n            {\n                var first = true;\n                var state = initialState;\n\n                while (!ct.IsCancellationRequested)\n                {\n                    var hasResult = false;\n                    var result = default(TResult);\n                    var nextDue = default(TimeSpan);\n\n                    try\n                    {\n                        if (first)\n                        {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs#L338-L374","documentation":"The fully-async Generate overload throws ArgumentNullException when the timeSelector delegate is null. timeSelector computes the per-element delay (TimeSpan in this overload); a null value would leave the scheduler with no delay to apply between OnNext emissions, so it is rejected upfront.","triggerScenarios":"Calling Generate(observer, initialState, condition, iterate, resultSelector, timeSelector, scheduler) with ValueTask delegates (Generate.cs:345) and passing null for Func<TState, ValueTask<TimeSpan>> timeSelector.","commonSituations":"Confusing overloads: the TimeSpan-based overload requires timeSelector while non-timed variants do not, so copying a call from a non-timed overload omits it; a delay-strategy object whose ToSelector() returned null.","solutions":["Supply a timeSelector, e.g. s => new ValueTask<TimeSpan>(TimeSpan.FromSeconds(1)).","If no delay is desired, pass s => new ValueTask<TimeSpan>(TimeSpan.Zero) instead of null.","Double-check which Generate overload you are calling and switch to the non-timed overload if you do not need per-element delays."],"exampleFix":"// before\nGenerate(observer, 0, cond, iter, sel, null, sched); // throws\n// after\nGenerate(observer, 0, cond, iter, sel, s => new ValueTask<TimeSpan>(TimeSpan.FromSeconds(1)), sched);","handlingStrategy":"validation","validationCode":"if (timeSelector == null) throw new ArgumentNullException(nameof(timeSelector));","typeGuard":"static bool HasTimeSelector<TState>(Func<TState, ValueTask<TimeSpan>> ts) => ts is not null;","tryCatchPattern":"try { await Generate(observer, state, cond, iter, sel, timeSel, sched); } catch (ArgumentNullException ex) when (ex.ParamName == \"timeSelector\") { /* fall back to TimeSpan.Zero selector */ }","preventionTips":["Use s => new ValueTask<TimeSpan>(TimeSpan.Zero) for no-delay generators rather than null.","Keep TimeSpan vs DateTimeOffset overloads straight; verify argument types match the overload.","Centralize delay policies in one non-null factory function."],"tags":["argument-null","generate","scheduler","async-rx"],"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"}