dotnet/reactive · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values…
Error message
Specified argument was out of the range of valid values. (Parameter 'skip')
What it means
This ArgumentOutOfRangeException is thrown by the count/skip-based Window helper when skip is zero or negative. skip controls how many source elements are dropped between window starts, so it must be a positive integer. The validation happens synchronously at call time.
Solutions
- Pass a positive skip (>= 1).
- Clamp before calling: skip = Math.Max(1, skip).
- Use the count-only Window overload if you don't need a stride.
- Validate the configuration value feeding skip and reject non-positive values early.
Example fix
// before var stride = settings.Skip; // 0 var windows = source.Window(5, stride); // after var stride = Math.Max(1, settings.Skip); var windows = source.Window(5, stride);
Defensive patterns
Strategy: validation
Validate before calling
if (skip < 1) throw new ArgumentOutOfRangeException(nameof(skip), skip, "Window skip must be positive."); // or clamp: skip = Math.Max(1, skip);
Type guard
bool IsValidSkip(int skip) => skip > 0;
Try / catch
try
{
var windows = source.Window(count, skip);
}
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "skip")
{
skip = 1; // tumbling windows
} Prevention
- Default stride configuration to 1, not 0.
- Validate both count and skip together since they come as a pair.
- Document that skip is a stride and must be >= 1.
When it happens
Trigger: Calling Window(source, count, skip) or the internal Window(observer, subscription, count, skip) with skip <= 0, e.g. a stride value read from settings as 0, or passing an offset variable that defaulted to 0.
Common situations: Configuring sliding windows where the stride was left at its default 0; copying an overload call and omitting a valid skip; computing skip from a percentage that rounds to 0.
Related errors
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- ArgumentOutOfRangeException
- Value cannot be null. (Parameter 'count')
- Value cannot be null. (Parameter 'source')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/43a5ddf8e17df372.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Window.cs:227
return subscription;
}
}
public partial class AsyncObserver
{
public static (IAsyncObserver<TSource>, IAsyncDisposable) Window<TSource>(IAsyncObserver<IAsyncObservable<TSource>> observer, IAsyncDisposable subscription, int count) => Window(observer, subscription, count, count);
public static (IAsyncObserver<TSource>, IAsyncDisposable) Window<TSource>(IAsyncObserver<IAsyncObservable<TSource>> observer, IAsyncDisposable subscription, int count, int skip)
{
if (observer == null)
throw new ArgumentNullException(nameof(observer));
if (subscription == null)
throw new ArgumentNullException(nameof(subscription));
if (count <= 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (skip <= 0)
throw new ArgumentOutOfRangeException(nameof(skip));
var refCount = new RefCountAsyncDisposable(subscription);
var queue = new Queue<IAsyncSubject<TSource>>();
var n = 0;
return
(
Create<TSource>
(
async x =>
{
foreach (var window in queue)
{
await window.OnNextAsync(x).ConfigureAwait(false);
}
var i = n - count + 1;View on GitHub (pinned to 94b5d5ab91)