{"record":{"id":"4475c9cd9462eb8d","repo":"dotnet/reactive","slug":"throw-new-argumentoutofrangeexception-nameof-timeshift","errorCode":null,"errorMessage":"throw new ArgumentOutOfRangeException(nameof(timeShift));","messagePattern":"throw new ArgumentOutOfRangeException\\(nameof\\(timeShift\\)\\);","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs","lineNumber":2301,"sourceCode":"        /// However, this doesn't mean all windows 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 window may not execute immediately, despite the TimeSpan.Zero due time.\n        /// </para>\n        /// </remarks>\n        public static IObservable<IObservable<TSource>> Window<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.Window(source, timeSpan, timeShift);\n        }\n\n        /// <summary>\n        /// Projects each element of an observable sequence into zero or more windows 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 windows in the result sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to produce windows over.</param>\n        /// <param name=\"timeSpan\">Length of each window.</param>\n        /// <param name=\"timeShift\">Interval between creation of consecutive windows.</param>\n        /// <param name=\"scheduler\">Scheduler to run windowing timers on.</param>\n        /// <returns>An observable sequence of windows.</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":2283,"sourceCodeEnd":2319,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs#L2283-L2319","documentation":"Window(source, timeSpan, timeShift) uses timeShift to control how far apart successive windows start, so it must be non-negative. The public method throws ArgumentOutOfRangeException when timeShift is negative, since a negative shift would make windows start before their predecessors — an ill-defined schedule.","triggerScenarios":"Calling Window(source, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(-5)) — any negative TimeSpan supplied as the timeShift parameter.","commonSituations":"A configurable 'shift' or 'interval' setting that was entered as a negative number; sign errors when the shift is computed as a difference of two times; accidentally swapping the timeSpan and timeShift parameters so a validated negative lands in the shift slot.","solutions":["Validate the shift duration is >= TimeSpan.Zero before the call, clamping if needed.","Fix the configuration or calculation producing the negative value.","Ensure timeSpan and timeShift arguments are not accidentally swapped.","Use a positive shift; for non-overlapping tumbling windows, set timeShift equal to timeSpan."],"exampleFix":"// before\nvar windows = source.Window(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(-5));\n// after\nvar shift = TimeSpan.FromSeconds(-5);\nif (shift < TimeSpan.Zero) shift = TimeSpan.Zero;\nvar windows = source.Window(TimeSpan.FromMinutes(1), shift);","handlingStrategy":"validation","validationCode":"if (timeShift < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(timeShift));","typeGuard":null,"tryCatchPattern":"try\n{\n    var windows = source.Window(timeSpan, timeShift);\n}\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"timeShift\")\n{\n    // fall back to shift == timeSpan for tumbling windows\n}","preventionTips":["Double-check argument order: (timeSpan, timeShift).","Clamp shift to zero when it may be negative.","For tumbling windows use timeShift == timeSpan; for sliding windows use 0 < timeShift < timeSpan."],"tags":["argument-out-of-range","timespan","rx"],"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"}