{"record":{"id":"557e42b5efe1d01d","repo":"dotnet/reactive","slug":"nameof-iterate","errorCode":null,"errorMessage":"nameof(iterate)","messagePattern":"nameof\\(iterate\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs","lineNumber":17,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Concurrency;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\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));","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs#L1-L35","documentation":"AsyncObservable.Generate requires an iterate function to advance the state and throws ArgumentNullException (parameter 'iterate') when it is null. Without an iterator the generated sequence could never progress, so the library rejects it eagerly.","triggerScenarios":"Calling AsyncObservable.Generate(initialState, condition, null, resultSelector) — the Func<TState,TState> step function is null, typically from an uninitialized member or a misordered argument list.","commonSituations":"Swapping the iterate and resultSelector arguments accidentally; a state-advance function resolved to null from configuration; incomplete refactoring leaving the lambda unassigned.","solutions":["Pass a non-null step function such as x => x + 1 for iterate","Check argument order: Generate(initialState, condition, iterate, resultSelector)","Add a null-check or default value where the iterate delegate is produced"],"exampleFix":"// before\nAsyncObservable.Generate(0, x => x < 10, null, x => x);\n// after\nAsyncObservable.Generate(0, x => x < 10, x => x + 1, x => x);","handlingStrategy":"validation","validationCode":"if (iterate == null)\n    throw new ArgumentNullException(nameof(iterate), \"Generate requires an iterate function\");\nvar obs = AsyncObservable.Generate(state, condition, iterate, resultSelector);","typeGuard":"static bool HasIterate<TState>(Func<TState, TState>? iterate) => iterate != null;","tryCatchPattern":"try\n{\n    var obs = AsyncObservable.Generate(state, condition, iterate, selector);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"iterate\")\n{\n    // supply a default step function or report config error\n}","preventionTips":["Keep condition/iterate/resultSelector in the documented order","Initialize delegate fields at declaration, not lazily","Validate delegates at the boundary where they are configured"],"tags":["null-argument","argumentnull","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"}