{"record":{"id":"2255588f495816c0","repo":"dotnet/reactive","slug":"condition-observable-time","errorCode":null,"errorMessage":"condition","messagePattern":"condition","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":745,"sourceCode":"\n        /// <summary>\n        /// Generates an observable sequence by running a state-driven and temporal loop producing the sequence's elements, using the specified scheduler to run timers and 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=\"timeSelector\">Time selector function to control the speed of values being produced each iteration.</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=\"timeSelector\"/> 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, Func<TState, DateTimeOffset> timeSelector, 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 (timeSelector == null)\n            {\n                throw new ArgumentNullException(nameof(timeSelector));\n            }\n\n            if (scheduler == null)","sourceCodeStart":727,"sourceCodeEnd":763,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L727-L763","documentation":"The scheduler-based timed Observable.Generate overload throws ArgumentNullException when the condition predicate (Func<TState, bool>) is null. condition determines when generation stops; without it the loop cannot be evaluated. Rx validates this eagerly at call time, before returning the observable.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector, scheduler) with condition == null, e.g. when the predicate is assembled dynamically, loaded from configuration, or omitted because a previous overload signature lacked it.","commonSituations":"Composing queries where the stop predicate is optional and passed straight through; refactoring from Reactive Extensions v2 style code where different Generate overloads existed; copy-paste between overloads dropping one argument.","solutions":["Pass an explicit stop predicate, e.g. state => state < 10.","If termination should never occur, use _ => true (with an external disposal mechanism) rather than null.","Guard with ArgumentNullException.ThrowIfNull(condition) at your own API boundary before forwarding to Generate."],"exampleFix":"// before\nvar xs = Observable.Generate(0, null, i => i + 1, i => i, i => TimeSpan.FromSeconds(1), Scheduler.Default);\n// after\nvar xs = Observable.Generate(0, i => i < 10, i => i + 1, i => i, i => TimeSpan.FromSeconds(1), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (condition == null)\n    throw new ArgumentNullException(nameof(condition));\nvar xs = Observable.Generate(initialState, condition, iterate, resultSelector, timeSelector, scheduler);","typeGuard":"bool HasCondition<TState>(Func<TState, bool> condition) => condition != null;","tryCatchPattern":"try\n{\n    var xs = Observable.Generate(state, cond, iter, sel, timeSel, scheduler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"condition\")\n{\n    logger.LogError(ex, \"Generate condition predicate was null\");\n}","preventionTips":["Model 'run forever' with _ => true instead of a null predicate.","Check delegate parameters positionally after refactoring overload calls — argument lists are long and easy to shift.","Use named arguments in Generate calls so dropped or swapped arguments fail at compile time."],"tags":["rx","argument-null","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"}