{"record":{"id":"b019a96021c353dd","repo":"dotnet/reactive","slug":"iterate","errorCode":null,"errorMessage":"iterate","messagePattern":"iterate","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":750,"sourceCode":"        /// <typeparam name=\"TResult\">The type of the elements in the produced sequence.</typeparam>\n        /// <param name=\"initialState\">Initial state.</param>\n        /// <param name=\"condition\">Condition to terminate generation (upon returning false).</param>\n        /// <param name=\"iterate\">Iteration step function.</param>\n        /// <param name=\"resultSelector\">Selector function for results produced in the sequence.</param>\n        /// <param name=\"timeSelector\">Time selector function to control the speed of values being produced each iteration.</param>\n        /// <param name=\"scheduler\">Scheduler on which to run the generator loop.</param>\n        /// <returns>The generated sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"condition\"/> or <paramref name=\"iterate\"/> or <paramref name=\"resultSelector\"/> or <paramref name=\"timeSelector\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        public static IObservable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, Func<TState, DateTimeOffset> timeSelector, IScheduler scheduler)\n        {\n            if (condition == null)\n            {\n                throw new ArgumentNullException(nameof(condition));\n            }\n\n            if (iterate == null)\n            {\n                throw new ArgumentNullException(nameof(iterate));\n            }\n\n            if (resultSelector == null)\n            {\n                throw new ArgumentNullException(nameof(resultSelector));\n            }\n\n            if (timeSelector == null)\n            {\n                throw new ArgumentNullException(nameof(timeSelector));\n            }\n\n            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Generate(initialState, condition, iterate, resultSelector, timeSelector, scheduler);","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L732-L768","documentation":"The scheduler-based timed Observable.Generate overload throws ArgumentNullException when the iterate function (Func<TState, TState>) is null. iterate advances the state between elements; without it Rx cannot progress the generation loop. The check runs eagerly before the observable is returned.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector, scheduler) with iterate == null, typically when the state-advancing function is conditionally constructed or accidentally omitted in a positional-argument call with many lambdas.","commonSituations":"Long argument lists of five delegates where one slot is skipped; dynamic query builders that fill lambdas from a dictionary of steps where the 'iterate' entry is missing; code generation or DSL output producing null.","solutions":["Provide a state transition function, e.g. i => i + 1.","If no state change is desired, use state => state as an explicit no-op iterator.","Validate all delegate parameters together at your wrapper's entry point so the failure is attributed to the right argument."],"exampleFix":"// before\nvar xs = Observable.Generate(0, i => i < 3, null, i => i, i => TimeSpan.Zero, Scheduler.Default);\n// after\nvar xs = Observable.Generate(0, i => i < 3, i => i + 1, i => i, i => TimeSpan.Zero, Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (iterate == null)\n    throw new ArgumentNullException(nameof(iterate));\nvar xs = Observable.Generate(initialState, condition, iterate, resultSelector, timeSelector, scheduler);","typeGuard":"bool HasIterator<TState>(Func<TState, TState> iterate) => iterate != null;","tryCatchPattern":"try\n{\n    var xs = Observable.Generate(state, cond, iter, sel, timeSel, scheduler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"iterate\")\n{\n    logger.LogError(ex, \"Generate iterate function was null\");\n}","preventionTips":["Use state => state as an explicit no-op iterator instead of null.","Keep Generate call sites small — wrap them in named helpers with validated parameters.","Run nullable reference type analysis (<Nullable>enable</Nullable>) so null delegate flow is flagged at compile time."],"tags":["rx","argument-null","generate"],"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"}