{"record":{"id":"bdd7d0abaf455deb","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-timerscheduler","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'timerScheduler')","messagePattern":"Value cannot be null\\. \\(Parameter 'timerScheduler'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":1285,"sourceCode":"        /// This operator accumulates a buffer with a length enough to store elements for any <paramref name=\"duration\"/> window during the lifetime of\n        /// the source sequence. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the result elements\n        /// to be delayed with <paramref name=\"duration\"/>.\n        /// </remarks>\n        public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler timerScheduler, IScheduler loopScheduler)\n        {\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>","sourceCodeStart":1267,"sourceCodeEnd":1303,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L1267-L1303","documentation":"TakeLast(source, duration, timerScheduler, loopScheduler) throws ArgumentNullException when timerScheduler is null. The timer scheduler drives the time-based buffering of elements, so it is mandatory in this overload. The library validates arguments eagerly at the public entry point.","triggerScenarios":"Calling TakeLast(source, TimeSpan.FromSeconds(5), null, loopScheduler); passing a scheduler field/property that was not initialized.","commonSituations":"Dependency-injected scheduler not registered in the container; static scheduler field not yet assigned in a test setup; refactoring that replaced DefaultScheduler with a nullable variable.","solutions":["Pass a non-null scheduler such as Scheduler.Default, TaskPoolScheduler.Default, or TestScheduler","Initialize the injected/field scheduler before building the query","Use the simpler TakeLast(source, duration) overload which uses the default scheduler"],"exampleFix":"// before\nvar res = source.TakeLast(TimeSpan.FromSeconds(5), null, loopScheduler);\n// after\nvar res = source.TakeLast(TimeSpan.FromSeconds(5), Scheduler.Default, loopScheduler);","handlingStrategy":"validation","validationCode":"if (timerScheduler == null) throw new ArgumentNullException(nameof(timerScheduler));","typeGuard":"bool HasTimerScheduler(IScheduler s) => s is not null;","tryCatchPattern":"try { var res = source.TakeLast(dur, timer, loop); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"timerScheduler\") { /* supply default scheduler */ }","preventionTips":["Default to Scheduler.Default when no scheduler is configured","Verify DI registrations resolve all scheduler dependencies at startup","In tests, initialize TestScheduler fields before composing queries"],"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"}