{"record":{"id":"fd53fa6da539386f","repo":"dotnetcore/CAP","slug":"specified-argument-was-out-of-the-range-of-valid-values-fd53fa","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'arrayIndex')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'arrayIndex'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.Dashboard/CircularBuffer.cs","lineNumber":162,"sourceCode":"        _items[itemIndex] = item;\n    }\n\n    public void Clear()\n    {\n        _firstIndex = 0;\n        Count = 0;\n    }\n\n    public bool Contains(T item)\n    {\n        throw new NotImplementedException();\n    }\n\n    public void CopyTo(T[] array, int arrayIndex)\n    {\n        if (array == null) throw new ArgumentNullException(nameof(array));\n\n        if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n\n        if (Count > array.Length - arrayIndex) throw new ArgumentException(\"arrayIndex\");\n\n        // Iterate through the buffer in correct order.\n        foreach (var item in this)\n        {\n            array[arrayIndex++] = item;\n        }\n    }\n\n    public bool Remove(T item)\n    {\n        throw new NotImplementedException();\n    }\n\n    #endregion\n}","sourceCodeStart":144,"sourceCodeEnd":179,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.Dashboard/CircularBuffer.cs#L144-L179","documentation":"CircularBuffer<T>.CopyTo throws ArgumentOutOfRangeException(\"arrayIndex\") when the starting offset is negative. The buffer requires a non-negative index into the destination array. A negative offset means caller index arithmetic went wrong before the copy.","triggerScenarios":"Calling CopyTo(array, index) with index < 0, e.g. an unvalidated caller-supplied offset or an underflowing computation like (size - capacity) used as the offset.","commonSituations":"Off-by-one/underflow in code computing a write position, user input parsed into an int offset without validation, or int subtraction wrapping below zero.","solutions":["Validate offset >= 0 before calling CopyTo (Math.Max(0, offset) if clamping is acceptable).","Fix the index computation that produced the negative value.","If the offset comes from external input, parse and range-check it explicitly."],"exampleFix":"// before\nint offset = current - capacity;\nbuffer.CopyTo(array, offset);\n// after\nint offset = Math.Max(0, current - capacity);\nif (offset >= 0) buffer.CopyTo(array, offset);","handlingStrategy":"validation","validationCode":"if (offset < 0) throw new InvalidOperationException(\"offset must be >= 0\");\nbuffer.CopyTo(array, offset);","typeGuard":null,"tryCatchPattern":"try { buffer.CopyTo(array, offset); }\ncatch (ArgumentOutOfRangeException) { /* clamp or log invalid offset */ }","preventionTips":["Clamp computed offsets with Math.Max(0, offset)","Range-check any externally supplied index before passing it on","Beware of int underflow when computing offsets from unsigned inputs"],"tags":["argument-out-of-range","collection","dashboard","dotnet"],"backgroundTag":"argument-out-of-range","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"}