{"record":{"id":"ba992af2585e8290","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-iterate-observable-creation","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":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":398,"sourceCode":"        /// <typeparam name=\"TState\">The type of the state used in the generator loop.</typeparam>\n        /// <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=\"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=\"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, 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 (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Generate(initialState, condition, iterate, resultSelector, scheduler);\n        }\n\n        #endregion\n\n        #region + Never +","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L380-L416","documentation":"The scheduler-overload of Observable.Generate throws ArgumentNullException when the 'iterate' delegate is null. The scheduled loop must advance state on every tick, so Rx rejects a null step function at the public API boundary.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, condition, null, resultSelector, scheduler), e.g. a step lambda that failed to initialize.","commonSituations":"Timer-like generators whose state-advance function is injected and not registered; mock setups returning null.","solutions":["Provide a non-null iterate function such as i => i + 1","Fall back to a no-op/terminating step if the step is optional","Assert the delegate is not null before invoking"],"exampleFix":"// before\nObservable.Generate(0, c, null, r, Scheduler.Default)\n// after\nObservable.Generate(0, c, i => i + 1, r, Scheduler.Default)","handlingStrategy":"validation","validationCode":"if (iterate == null) throw new ArgumentNullException(nameof(iterate));","typeGuard":"bool HasIterate(Func<TState,TState> it) => it is not null;","tryCatchPattern":"try { Observable.Generate(state, cond, it, sel, sched); } catch (ArgumentNullException ex) when (ex.ParamName == \"iterate\") { /* fix step function */ }","preventionTips":["Ensure mocked/injected step functions are registered in tests","Never leave nullable delegate parameters unset","Prefer a terminating condition over removing the step function"],"tags":["reactive","null-argument","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"}