{"record":{"id":"cd768fb1f223cfe8","repo":"stride3d/stride","slug":"invalid-offset-offset-or-count-count-for-source-length","errorCode":null,"errorMessage":"Invalid offset ({offset}) or count + ({count}) for source length {sourceLength}","messagePattern":"Invalid offset \\((.+?)\\) or count \\+ \\((.+?)\\) for source length (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":431,"sourceCode":"    /// <param name=\"offset\">The index into source at which the range begins.</param>\n    /// <param name=\"count\">The number of elements in the range.</param>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Either <paramref name=\"offset\"/> or <paramref name=\"count\"/> is less than 0.</exception>\n    /// <exception cref=\"ArgumentException\">The range [offset, offset + count) is not within the range [0, sourceLength).</exception>\n    private static void CheckRangeArguments(int sourceLength, int offset, int count)\n    {\n        if (offset < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(offset), \"Invalid offset \" + offset);\n        }\n\n        if (count < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(count), \"Invalid count \" + count);\n        }\n\n        if (sourceLength - offset < count)\n        {\n            throw new ArgumentException(\"Invalid offset (\" + offset + \") or count + (\" + count + \") for source length \" + sourceLength);\n        }\n    }\n\n    #endregion\n\n    /// <summary>\n    /// Gets a value indicating whether this instance is empty.\n    /// </summary>\n    private bool IsEmpty => Count == 0;\n\n    /// <summary>\n    /// Gets a value indicating whether this instance is at full capacity.\n    /// </summary>\n    private bool IsFull => Count == Capacity;\n\n    /// <summary>\n    /// Gets a value indicating whether the buffer is \"split\" (meaning the beginning of the view is at a later index in <see cref=\"buffer\"/> than the end).\n    /// </summary>","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L413-L449","documentation":"Thrown by CheckRangeArguments when the requested range [offset, offset+count) extends past the source: sourceLength - offset < count. This is an ArgumentException (not ArgumentOutOfRange) because neither parameter alone is wrong — the combination is invalid for the given source length.","triggerScenarios":"RemoveRange(offset, count) or a CopyTo path where offset + count > Count, e.g. RemoveRange(3, 10) on a 5-element deque.","commonSituations":"Using indices/lengths from a different (larger) collection; not refreshing Count after prior mutations; passing the source's capacity instead of its Count as the available length.","solutions":["Clamp count to Math.Min(count, deque.Count - offset) before calling","Check deque.Count immediately before the range operation","Ensure offset and count both derive from the same deque's current Count"],"exampleFix":"// before\ndeque.RemoveRange(offset, sliceLength); // sliceLength from another collection\n// after\ncount = Math.Min(sliceLength, deque.Count - offset);\ndeque.RemoveRange(offset, count);","handlingStrategy":"validation","validationCode":"count = Math.Min(count, deque.Count - offset);\nif (count < 0) count = 0;\ndeque.RemoveRange(offset, count);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure offset+count never exceeds the deque's current Count","Derive both offset and count from the same collection snapshot","Recheck Count after any intervening mutation"],"tags":["collections","deque","range","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}