dotnet/reactive · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException (default message: Specified…

Error message

ArgumentOutOfRangeException (default message: Specified argument was out of the range of valid values. (Parameter 'skip'))

What it means

Window(source, count, skip) requires skip > 0 and throws ArgumentOutOfRangeException naming 'skip' when skip <= 0. Skip determines how far the window start advances each time; zero or negative advances would loop or regress, so Rx rejects them eagerly.

Solutions

  1. Ensure skip >= 1 before calling Window (e.g. Math.Max(1, skip))
  2. Fix the config/computation producing the non-positive skip
  3. If no advancement is intended, Window(count, skip) is not the right operator — reconsider the windowing strategy

Example fix

// before
var windows = source.Window(10, stride); // stride = 0
// after
var windows = source.Window(10, Math.Max(1, stride));
Defensive patterns

Strategy: validation

Validate before calling

if (skip <= 0) throw new ArgumentOutOfRangeException(nameof(skip));
var safeSkip = Math.Max(1, skip);

Type guard

bool IsValidSkip(int skip) => skip > 0;

Try / catch

try { var w = source.Window(count, skip); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "skip") { /* clamp skip to 1 and retry */ }

Prevention

When it happens

Trigger: Calling source.Window(10, 0) or source.Window(10, -1); computing the skip from an interval/rate that can be zero (e.g. zero sampling period in config).

Common situations: Config where the 'stride' or 'overlap step' is set to 0; a rate/interval computed to 0 for instant processing; copy-paste overload changes where skip was accidentally replaced by 0 or a wrong variable.

Related errors


AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15). Data as JSON: /api/errors/46bb10a38f6d2d4b. Report an issue: GitHub.

Appendix: source

Thrown at Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs:1039

        /// <param name="skip">Number of elements to skip between creation of consecutive windows.</param>
        /// <returns>An observable sequence of windows.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> or <paramref name="skip"/> is less than or equal to zero.</exception>
        public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, int count, int skip)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (skip <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(skip));
            }

            return s_impl.Window(source, count, skip);
        }

        #endregion
    }
}

View on GitHub (pinned to 94b5d5ab91)