{"record":{"id":"e022733a71d3ca92","repo":"dotnet/reactive","slug":"specified-argument-was-out-of-the-range-of-valid-values-e02273","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'timeShift')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'timeShift'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":116,"sourceCode":"        /// However, this doesn't mean all buffers will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler,\n        /// where the action to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.\n        /// </para>\n        /// </remarks>\n        public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (timeSpan < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeSpan));\n            }\n\n            if (timeShift < TimeSpan.Zero)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeShift));\n            }\n\n            return s_impl.Buffer(source, timeSpan, timeShift);\n        }\n\n        /// <summary>\n        /// Projects each element of an observable sequence into zero or more buffers which are produced based on timing information, using the specified scheduler to run timers.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to produce buffers over.</param>\n        /// <param name=\"timeSpan\">Length of each buffer.</param>\n        /// <param name=\"timeShift\">Interval between creation of consecutive buffers.</param>\n        /// <param name=\"scheduler\">Scheduler to run buffering timers on.</param>\n        /// <returns>An observable sequence of buffers.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"scheduler\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"timeSpan\"/> or <paramref name=\"timeSpan\"/> is less than TimeSpan.Zero.</exception>\n        /// <remarks>\n        /// <para>","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L98-L134","documentation":"Buffer(source, timeSpan, timeShift) throws ArgumentOutOfRangeException when timeShift, the period between the starts of consecutive buffers, is negative. The shift must be zero or positive; negative shifts would move buffer boundaries into the past.","triggerScenarios":"Observable.Buffer(source, window, negativeShift), commonly when shift is computed as an offset subtraction that underflows, or when window/shift arguments are swapped and one is negative.","commonSituations":"Swapped arguments (passing the shift where the window belongs) with a negative value; negative config value for a polling/shift interval; dynamic rate calculations producing negative intervals.","solutions":["Clamp timeShift to TimeSpan.Zero or greater before the call","Verify argument order: Buffer(source, timeSpan, timeShift) — window first, shift second","Fix the computation or configuration that yields the negative shift"],"exampleFix":"// before\nsource.Buffer(window, latestTick - previousTick); // can be negative\n// after\nvar shift = latestTick > previousTick ? latestTick - previousTick : TimeSpan.Zero;\nsource.Buffer(window, shift);","handlingStrategy":"validation","validationCode":"if (timeShift < TimeSpan.Zero)\n    throw new ArgumentOutOfRangeException(nameof(timeShift), timeShift, \"Shift must be non-negative\");","typeGuard":"static bool IsValidShift(TimeSpan s) => s >= TimeSpan.Zero;","tryCatchPattern":"try { source.Buffer(window, shift); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"timeShift\")\n{\n    shift = TimeSpan.Zero;\n    source.Buffer(window, shift);\n}","preventionTips":["Double-check argument order when passing two TimeSpans: window first, shift second","Assert non-negativity where the shift is computed (rate/interval formulas)","Document in helper wrappers that negative shifts are rejected, so callers validate early"],"tags":["csharp","rx","argument-out-of-range","timespan"],"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-15T23:17:13.987Z"}