{"record":{"id":"1c9a14defb120789","repo":"stride3d/stride","slug":"invalid-count-count","errorCode":null,"errorMessage":"Invalid count {count}","messagePattern":"Invalid count (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":426,"sourceCode":"\n    /// <summary>\n    /// Checks the <paramref name=\"offset\"/> and <paramref name=\"count\"/> arguments for validity when applied to a source of a given length. Allows 0-element ranges, including a 0-element range at the end of the source.\n    /// </summary>\n    /// <param name=\"sourceLength\">The length of the source. This parameter is not checked for validity.</param>\n    /// <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>","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L408-L444","documentation":"Thrown by CheckRangeArguments when the count of a range operation is negative. Counts must be >= 0; the deque permits zero-element ranges but never negative ones. Raised as ArgumentOutOfRangeException naming 'count'.","triggerScenarios":"Calling CopyTo/RemoveRange-backed overloads with count < 0, e.g. RemoveRange(0, -2).","commonSituations":"Subtracting sizes in the wrong order (wanted - removed) yielding a negative count; int underflow in length computations; copying a 'remaining' value computed after over-advancing a cursor.","solutions":["Validate count >= 0 before the call","Fix the ordering of the subtraction that produces the count","Use Math.Max(0, computedCount) if a negative result should be treated as an empty range"],"exampleFix":"// before\ndeque.RemoveRange(offset, removedCount - keptCount); // may be negative\n// after\nint count = Math.Max(0, removedCount - keptCount);\ndeque.RemoveRange(offset, count);","handlingStrategy":"validation","validationCode":"if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));\ndeque.RemoveRange(offset, count);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate count >= 0 before range calls","Double-check subtraction order when computing counts","Clamp computed counts with Math.Max(0, n) where an empty range is acceptable"],"tags":["collections","deque","argument-out-of-range","count"],"backgroundTag":"argument-out-of-range","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"}