dotnet/reactive · error · ArgumentOutOfRangeException
count
Error message
count
What it means
Skip(source, count) throws ArgumentOutOfRangeException with paramName "count" when the caller passes a negative skip count. The library requires count >= 0; a negative count has no meaningful semantics (skipping fewer than zero elements).
Solutions
- Ensure the count passed to Skip is >= 0 before calling
- Clamp with Math.Max(0, count) when the value is derived from arithmetic or user input
- Fix paging math so page numbers are 1-based or clamped to at least 1
Example fix
// before var skip = (page - 1) * pageSize; var result = source.Skip(skip); // after var skip = Math.Max(0, (page - 1) * pageSize); var result = source.Skip(skip);
Defensive patterns
Strategy: validation
Validate before calling
if (count < 0) throw new ArgumentException("count must be >= 0", nameof(count));
source.Skip(count); Try / catch
try { var res = source.Skip(count); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "count") { /* clamp and retry */ } Prevention
- Clamp derived skip values with Math.Max(0, count)
- Validate paging inputs (page >= 1, size >= 0) at the boundary
- Never pass raw user input as a skip count without validation
When it happens
Trigger: Calling Skip(source, count) with a negative int, e.g. from an unvalidated user input or an arithmetic result that underflowed (count = taken - requested with taken < requested).
Common situations: Computing a skip count from paging math (page-1)*size where page is 0 or negative; subtracting counters that can go below zero; passing deserialized config values without validation.
Related errors
- Specified argument was out of the range of valid values…
- Specified argument was out of the range of valid values…
- duration
- 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/f3fb14dd1c131e35.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/Skip.cs:19
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
namespace System.Reactive.Linq
{
public partial class AsyncObservable
{
public static IAsyncObservable<TSource> Skip<TSource>(this IAsyncObservable<TSource> source, int count)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (count == 0)
{
return source;
}
return CreateAsyncObservable<TSource>.From(
source,
count,
static (source, count, observer) => source.SubscribeSafeAsync(AsyncObserver.Skip(observer, count)));
}
public static IAsyncObservable<TSource> Skip<TSource>(this IAsyncObservable<TSource> source, TimeSpan duration)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (duration < TimeSpan.Zero)
throw new ArgumentOutOfRangeException(nameof(duration));View on GitHub (pinned to 94b5d5ab91)