{"record":{"id":"7ce4e7f19fad46e7","repo":"dotnet/reactive","slug":"nameof-iterate-observable-creation","errorCode":null,"errorMessage":"nameof(iterate)","messagePattern":"nameof\\(iterate\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":366,"sourceCode":"        /// </summary>\n        /// <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        /// <returns>The generated sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"condition\"/> or <paramref name=\"iterate\"/> or <paramref name=\"resultSelector\"/> 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)\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            return s_impl.Generate(initialState, condition, iterate, resultSelector);\n        }\n\n        /// <summary>\n        /// Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.\n        /// </summary>\n        /// <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>","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L348-L384","documentation":"Observable.Generate throws ArgumentNullException when the 'iterate' (state-advancing) delegate is null. The operator must invoke iterate on every step to move from one state to the next, so Rx validates it up front and throws a descriptive ArgumentNullException rather than failing later.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, condition, null, resultSelector), e.g. a step function variable that is null or a lambda assigned to a null-able delegate field.","commonSituations":"Dynamically composed step functions where a factory returned null; typos assigning the lambda to the wrong variable; optional plugin hooks not wired.","solutions":["Pass a non-null iterate function, e.g. i => i + 1","Default a missing step function to a terminator such as _ => initialState to stop the loop","Validate the delegate before calling Generate"],"exampleFix":"// before\nObservable.Generate(0, c, null, r)\n// after\nObservable.Generate(0, c, i => i + 1, r)","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); } catch (ArgumentNullException ex) when (ex.ParamName == \"iterate\") { /* fix step function */ }","preventionTips":["Always supply a concrete step function; terminate via condition instead of a null step","Validate injected delegates at startup","Keep lambda construction close to the operator call"],"tags":["reactive","null-argument","linq"],"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"}