{"record":{"id":"67641984c313072f","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-loopscheduler","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'loopScheduler')","messagePattern":"Value cannot be null\\. \\(Parameter 'loopScheduler'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":1290,"sourceCode":"        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (duration < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(duration));\n            }\n\n            if (timerScheduler == null)\n            {\n                throw new ArgumentNullException(nameof(timerScheduler));\n            }\n\n            if (loopScheduler == null)\n            {\n                throw new ArgumentNullException(nameof(loopScheduler));\n            }\n\n            return s_impl.TakeLast(source, duration, timerScheduler, loopScheduler);\n        }\n\n        #endregion\n\n        #region + TakeLastBuffer +\n\n        /// <summary>\n        /// Returns a list with the elements within the specified duration from the end of the observable source sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to take elements from.</param>\n        /// <param name=\"duration\">Duration for taking elements from the end of the sequence.</param>\n        /// <returns>An observable sequence containing a single list with the elements taken during the specified duration from the end of the source sequence.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"duration\"/> is less than TimeSpan.Zero.</exception>","sourceCodeStart":1272,"sourceCodeEnd":1308,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L1272-L1308","documentation":"TakeLast(source, duration, timerScheduler, loopScheduler) throws ArgumentNullException when loopScheduler is null. The loop scheduler is used to run the buffering/concurrency loop of the operator and must be provided in this overload. Validation happens immediately at the call site.","triggerScenarios":"Calling TakeLast(source, TimeSpan.FromSeconds(5), timerScheduler, null); passing a null scheduler obtained from configuration or a factory that failed.","commonSituations":"Test harness that supplies a TestScheduler for the timer but forgets the loop scheduler; DI container missing a second scheduler registration; conditional scheduler resolution returning null.","solutions":["Pass a non-null loop scheduler (e.g. Scheduler.Default or ImmediateScheduler.Instance)","Register/initialize the loop scheduler in your DI container or test setup","Use the TakeLast(source, duration) overload that defaults both schedulers"],"exampleFix":"// before\nvar res = source.TakeLast(TimeSpan.FromSeconds(5), timerScheduler, null);\n// after\nvar res = source.TakeLast(TimeSpan.FromSeconds(5), timerScheduler, Scheduler.Default);","handlingStrategy":"validation","validationCode":"if (loopScheduler == null) throw new ArgumentNullException(nameof(loopScheduler));","typeGuard":"bool HasLoopScheduler(IScheduler s) => s is not null;","tryCatchPattern":"try { var res = source.TakeLast(dur, timer, loop); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"loopScheduler\") { /* supply default scheduler */ }","preventionTips":["Pass Scheduler.Default for the loop scheduler unless a specific one is required","Register both timer and loop schedulers together in DI to avoid partial wiring","Prefer the single-scheduler TakeLast(duration) overload when no custom loop scheduling is needed"],"tags":["argument-null","scheduler","reactive-extensions"],"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"}