{"record":{"id":"088321c3b49cd7bb","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-condition","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(condition));","messagePattern":"throw new ArgumentNullException\\(nameof\\(condition\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":627,"sourceCode":"        #region + Generate +\n\n        /// <summary>\n        /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements.\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>\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        /// <returns>The generated sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"condition\"/> or <paramref name=\"iterate\"/> or <paramref name=\"resultSelector\"/> or <paramref name=\"timeSelector\"/> 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, TimeSpan> timeSelector)\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            return s_impl.Generate(initialState, condition, iterate, resultSelector, timeSelector);","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L609-L645","documentation":"Observable.Generate with a time selector validates every delegate; it throws ArgumentNullException when the condition predicate is null. Generate produces values from initialState while condition(state) holds, so the loop cannot run without a predicate.","triggerScenarios":"Calling Generate(initialState, condition, iterate, resultSelector, timeSelector) with a null condition delegate — typically a dynamically chosen predicate that resolved to null.","commonSituations":"Predicate built from nullable config or a strategy pattern with an unregistered branch; also typos where condition was accidentally assigned from a void-returning setup method.","solutions":["Pass a real predicate, e.g. x => x < 10 (use _ => true for an effectively infinite sequence bounded elsewhere).","If conditionality is intentional, supply x => true rather than null.","Fix the predicate factory/dictionary lookup returning null."],"exampleFix":"// before\nvar cond = rules.TryGetValue(name, out var c) ? c : null;\nObservable.Generate(0, cond, x => x + 1, x => x, x => TimeSpan.FromSeconds(1));\n// after\nvar cond = rules.TryGetValue(name, out var c) ? c : (Func<int, bool>)(_ => true);\nObservable.Generate(0, cond, x => x + 1, x => x, x => TimeSpan.FromSeconds(1));","handlingStrategy":"validation","validationCode":"if (condition == null) throw new InvalidOperationException(\"Generate requires a condition predicate\");","typeGuard":"static Func<T,bool> RequirePredicate<T>(Func<T,bool> p) => p ?? throw new InvalidOperationException(\"predicate required\");","tryCatchPattern":"try { Observable.Generate(state, condition, iterate, result, timeSel).Subscribe(...); }\ncatch (ArgumentNullException ex) { log.LogError(\"Generate missing delegate: {Param}\", ex.ParamName); }","preventionTips":["Use _ => true when a bounded infinite sequence is intended","Resolve strategy/dictionary-based predicates with explicit fallbacks","Validate all five delegates at once before calling Generate"],"tags":["rx","argument-null","generate","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"}