{"record":{"id":"9db256e9b6748836","repo":"dotnetcore/CAP","slug":"specified-argument-was-out-of-the-range-of-valid-values-9db256","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'zeroBasedIndex')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'zeroBasedIndex'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.Dashboard/CircularBuffer.cs","lineNumber":81,"sourceCode":"\n            return _items[WrapIndex(index)];\n        }\n    }\n\n    /// <summary>\n    /// Convert from a 0-based index to a buffer index which\n    /// has been properly offset and wrapped.\n    /// </summary>\n    /// <param name=\"zeroBasedIndex\">The index to wrap.</param>\n    /// <exception cref=\"ArgumentOutOfRangeException\">If <paramref name=\"zeroBasedIndex\" /> is out of range.</exception>\n    /// <returns>\n    /// The actual index that\n    /// <param ref=\"zeroBasedIndex\" />\n    /// maps to.\n    /// </returns>\n    private int WrapIndex(int zeroBasedIndex)\n    {\n        if (Capacity == 0 || zeroBasedIndex < 0) throw new ArgumentOutOfRangeException(nameof(zeroBasedIndex));\n\n        return (zeroBasedIndex + _firstIndex) % Capacity;\n    }\n\n    /// <summary>\n    /// Create an array of the items in the buffer. Items\n    /// will be in the same order they were added.\n    /// </summary>\n    /// <returns>The new array.</returns>\n    public T[] ToArray()\n    {\n        var result = new T[Count];\n        CopyTo(result, 0);\n        return result;\n    }\n\n    #region IEnumerable<T> implementation.\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.Dashboard/CircularBuffer.cs#L63-L99","documentation":"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).","triggerScenarios":"Thrown at src/DotNetCore.CAP.Dashboard/CircularBuffer.cs:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Guard caller-side: verify 0 <= index < Count before accessing the indexer","Ensure the buffer has been populated (Count > 0) before enumeration or indexing","Wrap access in a try/catch ArgumentOutOfRangeException when the index source is untrusted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}