{"record":{"id":"4c69bfad61aad5f0","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-4c69bf","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'duration')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'duration'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":1322,"sourceCode":"        /// <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>\n        /// <remarks>\n        /// 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 produced on the result sequence.\n        /// </remarks>\n        public static IObservable<IList<TSource>> TakeLastBuffer<TSource>(this IObservable<TSource> source, TimeSpan duration)\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            return s_impl.TakeLastBuffer(source, duration);\n        }\n\n        /// <summary>\n        /// Returns a list with the elements within the specified duration from the end of the observable source sequence, using the specified scheduler to run timers.\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        /// <param name=\"scheduler\">Scheduler to run the timer on.</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\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"duration\"/> is less than TimeSpan.Zero.</exception>\n        /// <remarks>\n        /// 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 produced on the result sequence.","sourceCodeStart":1304,"sourceCodeEnd":1340,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L1304-L1340","documentation":"TakeLastBuffer(source, duration) throws ArgumentOutOfRangeException when the duration TimeSpan is negative. Only non-negative time windows are meaningful for collecting the trailing buffer, so the library rejects negative values before delegating to the implementation.","triggerScenarios":"Calling TakeLastBuffer(source, TimeSpan.FromSeconds(-3)); computing the window via subtraction where the end time precedes the start time.","commonSituations":"User-supplied window configuration that can go negative; DateTime subtraction across clock adjustments; off-by-sign bugs in generated durations.","solutions":["Validate the TimeSpan is >= TimeSpan.Zero before calling","Clamp negative durations to TimeSpan.Zero or fix the computation","Correct the source of the timestamps/configuration that produced the negative value"],"exampleFix":"// before\nvar buf = source.TakeLastBuffer(windowEnd - windowStart);\n// after\nvar dur = windowEnd - windowStart;\nif (dur < TimeSpan.Zero) throw new InvalidOperationException(\"window end before start\");\nvar buf = source.TakeLastBuffer(dur);","handlingStrategy":"validation","validationCode":"if (duration < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(duration));","typeGuard":null,"tryCatchPattern":"try { var buf = source.TakeLastBuffer(dur); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"duration\") { /* clamp or report config error */ }","preventionTips":["Clamp durations to TimeSpan.Zero minimum before use","Validate window configuration at load time","Compute windows with explicit ordering checks (start <= end)"],"tags":["argument-out-of-range","timespan","reactive-extensions"],"backgroundTag":"argument-out-of-range","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"}