{"record":{"id":"f4e8490963bf3929","repo":"dotnet/reactive","slug":"new-argumentnullexception-nameof-condition","errorCode":null,"errorMessage":"new ArgumentNullException(nameof(condition))","messagePattern":"new ArgumentNullException\\(nameof\\(condition\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs","lineNumber":350,"sourceCode":"                throw new ArgumentNullException(nameof(observer));\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 (timeSelector == null)\n                throw new ArgumentNullException(nameof(timeSelector));\n\n            return Generate(observer, initialState, condition, iterate, resultSelector, timeSelector, TaskPoolAsyncScheduler.Default);\n        }\n\n        public static ValueTask<IAsyncDisposable> Generate<TState, TResult>(IAsyncObserver<TResult> observer, TState initialState, Func<TState, ValueTask<bool>> condition, Func<TState, ValueTask<TState>> iterate, Func<TState, ValueTask<TResult>> resultSelector, Func<TState, ValueTask<TimeSpan>> timeSelector, IAsyncScheduler scheduler)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\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 (timeSelector == null)\n                throw new ArgumentNullException(nameof(timeSelector));\n            if (scheduler == null)\n                throw new ArgumentNullException(nameof(scheduler));\n\n            return scheduler.ScheduleAsync(async ct =>\n            {\n                var first = true;\n                var state = initialState;\n\n                while (!ct.IsCancellationRequested)\n                {\n                    var hasResult = false;\n                    var result = default(TResult);","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Generate.cs#L332-L368","documentation":"The explicit-scheduler Generate overload validates condition (Func<TState, ValueTask<bool>>) second and throws ArgumentNullException(nameof(condition)) when null. Since condition is the loop's only termination mechanism, null is rejected before scheduling begins.","triggerScenarios":"Generate(observer, initialState, condition: null, iterate, resultSelector, timeSelector, scheduler) on the 7-argument overload.","commonSituations":"Predicate built from user configuration that is null when the setting is absent; refactoring between overloads and dropping the condition argument.","solutions":["Pass a terminating predicate delegate, e.g. s => new ValueTask<bool>(s < limit).","Fall back to a default predicate when the configured one is missing (e.g. always-false to generate once, or a count bound).","Validate configuration inputs before composing the operator chain."],"exampleFix":"// before\nGenerate(observer, 0, configuredCondition /* null */, iterate, select, timing, scheduler);\n// after\nvar condition = configuredCondition ?? (Func<int, ValueTask<bool>>)(s => new ValueTask<bool>(s < 100));\nGenerate(observer, 0, condition, iterate, select, timing, scheduler);","handlingStrategy":"validation","validationCode":"if (condition == null) throw new ArgumentNullException(nameof(condition));","typeGuard":"bool IsValidCondition<TState>(Func<TState, ValueTask<bool>> f) => f != null;","tryCatchPattern":"try { await Generate(observer, state, cond, iterate, select, timing, scheduler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"condition\") { /* apply a default bounded predicate */ }","preventionTips":["Null-coalesce configured predicates with a safe default","Use named arguments for the 7-argument overload","Fail early in your own factory methods when config produces a null predicate"],"tags":["argument-null","generate-operator","argument-validation"],"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"}