{"record":{"id":"58a4ff9deb3c62ce","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-condition-observable-creation","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'condition')","messagePattern":"Value cannot be null\\. \\(Parameter 'condition'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs","lineNumber":393,"sourceCode":"        }\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>\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);","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Creation.cs#L375-L411","documentation":"The scheduler-overload of Observable.Generate throws ArgumentNullException when the 'condition' predicate is null. All delegates must be non-null because the scheduled generator loop invokes condition each step to decide whether to keep producing elements.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, null, iterate, resultSelector, scheduler) — e.g. a predicate loaded from configuration that was absent.","commonSituations":"Scheduler-based generators built from dynamic rules engines; test harnesses parameterizing predicates where one parameter stayed null.","solutions":["Pass a valid condition predicate like x => x < 10","Default an absent predicate to _ => true","Guard the argument before the call"],"exampleFix":"// before\nObservable.Generate(0, null, i => i + 1, i => i, Scheduler.Default)\n// after\nObservable.Generate(0, x => x < 10, i => i + 1, i => i, Scheduler.Default)","handlingStrategy":"validation","validationCode":"if (condition == null) throw new ArgumentNullException(nameof(condition));","typeGuard":"bool HasCondition(Func<TState,bool> c) => c is not null;","tryCatchPattern":"try { Observable.Generate(state, cond, it, sel, sched); } catch (ArgumentNullException ex) when (ex.ParamName == \"condition\") { /* supply default */ }","preventionTips":["Default missing predicates to _ => true","Validate rule-driven delegates before scheduling","Null-check all Generate arguments in one guard helper"],"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"}