{"record":{"id":"12e4454fec585aa6","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-iterate","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'iterate')","messagePattern":"Value cannot be null\\. \\(Parameter 'iterate'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs","lineNumber":29,"sourceCode":"    {\n        public static IAsyncObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector)\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\n            return Create<TResult>(observer => AsyncObserver.Generate(observer, initialState, condition, iterate, resultSelector));\n        }\n\n        public static IAsyncObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, 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 (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, ValueTask<bool>> condition, Func<TState, ValueTask<TState>> iterate, Func<TState, ValueTask<TResult>> resultSelector)\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\n            return Create<TResult>(observer => AsyncObserver.Generate(observer, initialState, condition, iterate, resultSelector));","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs#L11-L47","documentation":"The scheduler-based Generate overload throws ArgumentNullException with parameter name 'iterate' when the state-advance function is null. The full .NET message is 'Value cannot be null. (Parameter 'iterate')'.","triggerScenarios":"Calling AsyncObservable.Generate(initialState, condition, null, resultSelector, scheduler) — null step function while specifying a scheduler, e.g. when building arguments programmatically.","commonSituations":"A null iterate delegate coming from DI or config; five-argument call where an optional lambda was omitted but null was passed explicitly; refactors that reordered parameters.","solutions":["Provide a non-null step function like x => x + 1 for the third argument","Check argument positions against the (initialState, condition, iterate, resultSelector, scheduler) signature","Fail fast at construction of the delegates: if (iterate == null) throw earlier in your own factory"],"exampleFix":"// before\nAsyncObservable.Generate(0, x => x < 10, null, x => x, Scheduler.Default);\n// after\nAsyncObservable.Generate(0, x => x < 10, x => x + 1, x => x, Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (iterate == null)\n    throw new ArgumentNullException(nameof(iterate));\nvar obs = AsyncObservable.Generate(state, condition, iterate, resultSelector, scheduler);","typeGuard":"static bool HasStep<TState>(Func<TState, TState>? iterate) => iterate != null;","tryCatchPattern":"try\n{\n    var obs = AsyncObservable.Generate(state, condition, iterate, selector, scheduler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"iterate\")\n{\n    logger.LogError(\"Missing iterate delegate for scheduled Generate\");\n}","preventionTips":["Avoid explicit null literals in five-argument calls","Resolve iterate from a source guaranteed non-null","Fail at configuration time, not at observable construction"],"tags":["null-argument","argumentnull","scheduler"],"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"}