AvaloniaUI/Avalonia · error · ArgumentException

Skip count must be bigger than zero

Error message

Skip count must be bigger than zero

What it means

Thrown by Observable.Skip<T> when skipCount is less than or equal to zero. Skip is meant to drop the first N notifications of a stream; skipping zero or a negative count is a programming error (use the source directly). Note the message says 'must be bigger than zero' and the guard is skipCount <= 0, so skipCount of exactly 0 also throws.

Source

Thrown at src/Avalonia.Base/Reactive/Observable.cs:105

    public static IObservable<TResult> CombineLatest<TFirst, TSecond, TResult>(
        this IObservable<TFirst> first, IObservable<TSecond> second,
        Func<TFirst, TSecond, TResult> resultSelector)
    {
        return new CombineLatest<TFirst, TSecond, TResult>(first, second, resultSelector);
    }
    
    public static IObservable<TInput[]> CombineLatest<TInput>(
        this IEnumerable<IObservable<TInput>> inputs)
    {
        return new CombineLatest<TInput, TInput[]>(inputs, items => items);
    }

    public static IObservable<T> Skip<T>(this IObservable<T> source, int skipCount)
    {
        if (skipCount <= 0)
        {
            throw new ArgumentException("Skip count must be bigger than zero", nameof(skipCount));
        }

        return Create<T>(obs =>
        {
            var remaining = skipCount;
            return source.Subscribe(new AnonymousObserver<T>(
                input =>
                {
                    if (remaining <= 0)
                    {
                        obs.OnNext(input);
                    }
                    else
                    {
                        remaining--;
                    }
                }, obs.OnError, obs.OnCompleted));
        });

View on GitHub (pinned to 11c5427268)

Solutions

  1. If you want all items, skip the Skip call entirely when count <= 0.
  2. Clamp the count: source.Skip(Math.Max(1, count)) only when you genuinely want to skip at least one.
  3. Validate count > 0 before calling and surface a clearer error to your caller.

Example fix

// before
var filtered = source.Skip(skipCount); // throws when skipCount == 0
// after
var filtered = skipCount > 0 ? source.Skip(skipCount) : source;
Defensive patterns

Strategy: validation

Validate before calling

if (skipCount <= 0) throw new ArgumentOutOfRangeException(nameof(skipCount));
var s = skipCount > 0 ? source.Skip(skipCount) : source;

Prevention

When it happens

Trigger: Calling source.Skip(0), source.Skip(-1), or source.Skip(count) where count is computed from user input or a config value that can be zero/negative.

Common situations: A 'skip first N items' feature where N is user-configurable and defaults to or can be set to 0; an off-by-one producing a negative; reusing the same variable for both skip and take and letting it hit 0.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/ee4949d28230d038. Report an issue: GitHub.