dotnetcore/CAP · 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 'zeroBasedIndex')

What it means

ArgumentOutOfRangeException from the private WrapIndex helper, which validates zeroBasedIndex against the buffer's Count/Capacity before offsetting and wrapping. It fires when a 0-based index passed by the indexer or the enumerator is negative or beyond the number of stored items (including when Capacity == 0).

Solutions

  1. Guard caller-side: verify 0 <= index < Count before accessing the indexer
  2. Ensure the buffer has been populated (Count > 0) before enumeration or indexing
  3. Wrap access in a try/catch ArgumentOutOfRangeException when the index source is untrusted
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/DotNetCore.CAP.Dashboard/CircularBuffer.cs:81 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnetcore/CAP@e52b8508e5 (2026-09-14). Data as JSON: /api/errors/9db256e9b6748836. Report an issue: GitHub.

Appendix: source

Thrown at src/DotNetCore.CAP.Dashboard/CircularBuffer.cs:81

            return _items[WrapIndex(index)];
        }
    }

    /// <summary>
    /// Convert from a 0-based index to a buffer index which
    /// has been properly offset and wrapped.
    /// </summary>
    /// <param name="zeroBasedIndex">The index to wrap.</param>
    /// <exception cref="ArgumentOutOfRangeException">If <paramref name="zeroBasedIndex" /> is out of range.</exception>
    /// <returns>
    /// The actual index that
    /// <param ref="zeroBasedIndex" />
    /// maps to.
    /// </returns>
    private int WrapIndex(int zeroBasedIndex)
    {
        if (Capacity == 0 || zeroBasedIndex < 0) throw new ArgumentOutOfRangeException(nameof(zeroBasedIndex));

        return (zeroBasedIndex + _firstIndex) % Capacity;
    }

    /// <summary>
    /// Create an array of the items in the buffer. Items
    /// will be in the same order they were added.
    /// </summary>
    /// <returns>The new array.</returns>
    public T[] ToArray()
    {
        var result = new T[Count];
        CopyTo(result, 0);
        return result;
    }

    #region IEnumerable<T> implementation.

View on GitHub (pinned to e52b8508e5)