dotnet/reactive · error · ArgumentOutOfRangeException
throw new ArgumentOutOfRangeException(nameof(timeShift));
Error message
throw new ArgumentOutOfRangeException(nameof(timeShift));
What it means
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.
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.
Example fix
// before var windows = source.Window(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(-5)); // after var shift = TimeSpan.FromSeconds(-5); if (shift < TimeSpan.Zero) shift = TimeSpan.Zero; var windows = source.Window(TimeSpan.FromMinutes(1), shift);
Defensive patterns
Strategy: validation
Validate before calling
if (timeShift < TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(timeShift));
Try / catch
try
{
var windows = source.Window(timeSpan, timeShift);
}
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "timeShift")
{
// fall back to shift == timeSpan for tumbling windows
} Prevention
- 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.
When it happens
Trigger: Calling Window(source, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(-5)) — any negative TimeSpan supplied as the timeShift parameter.
Common situations: 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.
Related errors
- duration
- interval
- period (Parameter 'period')
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/4475c9cd9462eb8d.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Time.cs:2301
/// 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,
/// where the action to create a new window may not execute immediately, despite the TimeSpan.Zero due time.
/// </para>
/// </remarks>
public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
if (timeSpan < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(timeSpan));
}
if (timeShift < TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(timeShift));
}
return s_impl.Window(source, timeSpan, timeShift);
}
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam>
/// <param name="source">Source sequence to produce windows over.</param>
/// <param name="timeSpan">Length of each window.</param>
/// <param name="timeShift">Interval between creation of consecutive windows.</param>
/// <param name="scheduler">Scheduler to run windowing timers on.</param>
/// <returns>An observable sequence of windows.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
/// <exception cref="ArgumentOutOfRangeException"><paramref name="timeSpan"/> or <paramref name="timeSpan"/> is less than TimeSpan.Zero.</exception>
/// <remarks>
/// <para>View on GitHub (pinned to 94b5d5ab91)