{"record":{"id":"3616effa588533fc","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-timeselector","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'timeSelector')","messagePattern":"Value cannot be null\\. \\(Parameter 'timeSelector'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs","lineNumber":73,"sourceCode":"                throw new ArgumentNullException(nameof(iterate));\n            if (resultSelector == null)\n                throw new ArgumentNullException(nameof(resultSelector));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return Create<TResult>(observer => AsyncObserver.Generate(observer, initialState, condition, iterate, resultSelector, scheduler));\n        }\n\n        public static IAsyncObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, TimeSpan> timeSelector)\n        {\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\n            return Create<TResult>(observer => AsyncObserver.Generate(observer, initialState, condition, iterate, resultSelector, timeSelector));\n        }\n\n        public static IAsyncObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, TimeSpan> timeSelector, IAsyncScheduler scheduler)\n        {\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 Create<TResult>(observer => AsyncObserver.Generate(observer, initialState, condition, iterate, resultSelector, timeSelector, scheduler));","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs#L55-L91","documentation":"Generate requires a timeSelector delegate that maps each state to the delay before the next element. When it is null, this overload throws ArgumentNullException immediately. This instance comes from the synchronous 5-parameter Generate overload (no scheduler).","triggerScenarios":"Calling AsyncObservable.Generate(initialState, condition, iterate, resultSelector, timeSelector) with timeSelector == null, typically because a TimeSpan-returning lambda was omitted or a null variable was passed.","commonSituations":"Dynamically composed pipelines where timing lambdas come from settings that failed to load; wrong overload picked (using the sync overload where the async ValueTask overload was intended) so the argument slot is null.","solutions":["Supply a non-null timeSelector, e.g. state => TimeSpan.FromMilliseconds(50).","For constant delays, pass a lambda returning a fixed TimeSpan instead of null.","Verify you are invoking the overload matching your delegate types (sync vs ValueTask-returning)."],"exampleFix":"// before\nvar src = AsyncObservable.Generate(0, i => i < 5, i => i + 1, i => i, (Func<int, TimeSpan>)null);\n// after\nvar src = AsyncObservable.Generate(0, i => i < 5, i => i + 1, i => i, _ => TimeSpan.FromSeconds(1));","handlingStrategy":"validation","validationCode":"if (timeSelector is null) timeSelector = _ => TimeSpan.Zero;\nvar src = AsyncObservable.Generate(initialState, condition, iterate, resultSelector, timeSelector);","typeGuard":"static bool HasTimeSelector<TState>(Func<TState,TimeSpan> t) => t != null;","tryCatchPattern":"try\n{\n    var src = AsyncObservable.Generate(initialState, condition, iterate, resultSelector, timeSelector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"timeSelector\")\n{\n    // substitute a default delay and retry construction\n}","preventionTips":["Default the delay to TimeSpan.Zero at the call site instead of relying on the library.","Keep timing lambdas near the Generate call, not in nullable remote config.","Use named arguments to make every delegate slot explicit."],"tags":["asyncrx","null-argument","generate-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-23T08:17:48.524Z"}