{"record":{"id":"facdeb971232800a","repo":"dotnet/reactive","slug":"throw-new-argumentnullexception-nameof-timeselector","errorCode":null,"errorMessage":"throw new ArgumentNullException(nameof(timeSelector));","messagePattern":"throw new ArgumentNullException\\(nameof\\(timeSelector\\)\\);","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":642,"sourceCode":"        {\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);\n        }\n\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>","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L624-L660","documentation":"Observable.Generate (the TimeSpan overload, no scheduler) throws ArgumentNullException because the timeSelector delegate was null. The timeSelector decides the delay before each element, so Rx requires it non-null at call time. Provide a Func<TState, TimeSpan> returning the per-element delay.","triggerScenarios":"Calling Observable.Generate(initialState, condition, iterate, resultSelector, timeSelector: null) — e.g. omitting the timing lambda when converting a plain Generate call into a timed one.","commonSituations":"Migrating from the non-timed Observable.Generate overload to the timed one and forgetting the extra delegate; building the timing function from configuration that was not loaded.","solutions":["Pass a non-null Func<TState, TimeSpan> as timeSelector (e.g. _ => TimeSpan.FromSeconds(1)).","Use the non-timed Observable.Generate overload if no per-element delay is wanted.","Check that the config-derived delay function is initialized before the call."],"exampleFix":"// before\nvar xs = Observable.Generate(0, i => i < 5, i => i + 1, i => i, (Func<int, TimeSpan>)null);\n// after\nvar xs = Observable.Generate(0, i => i < 5, i => i + 1, i => i, _ => TimeSpan.FromSeconds(1));","handlingStrategy":"validation","validationCode":"if (timeSelector is null) throw new InvalidOperationException(\"timeSelector must be provided for the timed Generate overload\");","typeGuard":"static bool HasTimeSelector<TState>(Func<TState, TimeSpan> timeSelector) => timeSelector is not null;","tryCatchPattern":"try { var xs = Observable.Generate(0, cond, iter, sel, timeSelector); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"timeSelector\") { /* use non-timed Generate instead */ }","preventionTips":["If no delay is needed, call the non-timed Generate overload instead of passing null.","Give timing functions a non-null default (e.g. _ => TimeSpan.Zero).","Watch for dropped arguments when migrating from plain Generate to the timed overload."],"tags":["null-argument","rx","linq","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-23T08:17:48.524Z"}