{"record":{"id":"16011a8b96a98f81","repo":"dotnet/reactive","slug":"timeselector","errorCode":null,"errorMessage":"timeSelector","messagePattern":"timeSelector","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":760,"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            if (scheduler == null)\n            {\n                throw new ArgumentNullException(nameof(scheduler));\n            }\n\n            return s_impl.Generate(initialState, condition, iterate, resultSelector, timeSelector, scheduler);\n        }\n\n        #endregion\n\n        #region + Interval +\n\n        /// <summary>\n        /// Returns an observable sequence that produces a value after each period.\n        /// </summary>\n        /// <param name=\"period\">Period for producing the values in the resulting sequence. If this value is equal to TimeSpan.Zero, the timer will recur as fast as possible.</param>","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L742-L778","documentation":"The scheduler-based timed Observable.Generate overload throws ArgumentNullException when timeSelector (Func<TState, DateTimeOffset>) is null. timeSelector yields the absolute due time for each element; without it scheduling is impossible. Validation is eager, thrown synchronously at the call site.","triggerScenarios":"Calling Observable.Generate<TState, TResult>(initialState, condition, iterate, resultSelector, timeSelector, scheduler) with timeSelector == null, e.g. when the absolute-time function is derived from user settings that are absent, or an overload mix-up passed a TimeSpan-based selector where DateTimeOffset was expected and the variable stayed null.","commonSituations":"Switching between the TimeSpan-based and DateTimeOffset-based Generate overloads during migration; calendar/simulation schedulers where the time function comes from injected services that returned null.","solutions":["Supply an absolute-time selector, e.g. state => startTime.AddSeconds(state).","Use the TimeSpan-based overload (relative times) if that matches your data instead.","Default to a constant increment: state => scheduler.Now.Add(TimeSpan.FromSeconds(1)) when per-state timing is unnecessary."],"exampleFix":"// before\nvar xs = Observable.Generate(0, i => i < 5, i => i + 1, i => i, null, Scheduler.Default);\n// after\nvar start = DateTimeOffset.Now;\nvar xs = Observable.Generate(0, i => i < 5, i => i + 1, i => i, i => start.AddSeconds(i), Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (timeSelector == null)\n    throw new ArgumentNullException(nameof(timeSelector));\nvar xs = Observable.Generate(initialState, condition, iterate, resultSelector, timeSelector, scheduler);","typeGuard":"bool HasTimeSelector<TState>(Func<TState, DateTimeOffset> timeSelector) => timeSelector != null;","tryCatchPattern":"try\n{\n    var xs = Observable.Generate(state, cond, iter, sel, timeSel, scheduler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"timeSelector\")\n{\n    logger.LogError(ex, \"Generate timeSelector (DateTimeOffset) was null\");\n}","preventionTips":["Do not mix TimeSpan-based and DateTimeOffset-based selector variables; name them clearly (relativeTimeSelector vs absoluteTimeSelector).","Derive absolute-time selectors from a captured start time so they are always constructible.","Add unit tests that construct every Generate overload once to catch signature mix-ups."],"tags":["rx","argument-null","scheduling"],"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"}