{"record":{"id":"b4b4f04198cf149e","repo":"louthy/language-ext","slug":"argumentoutofrangeexception","errorCode":null,"errorMessage":"ArgumentOutOfRangeException","messagePattern":"ArgumentOutOfRangeException","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/Arr/Arr.cs","lineNumber":94,"sourceCode":"    /// <summary>\n    /// Ctor\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    internal Arr(A[] value)\n    {\n        hashCode = Atom(0);\n        this.value = value;\n        start = 0;\n        length = value.Length;\n    }\n\n    /// <summary>\n    /// Ctor\n    /// </summary>\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    internal Arr(A[] value, int start, int length)\n    {\n        if(start < 0) throw new ArgumentOutOfRangeException(nameof(start));\n        if(start + length > value.Length) throw new ArgumentOutOfRangeException(nameof(length));\n        hashCode = Atom(0);\n        this.value = value;\n        this.start = start;\n        this.length = length;\n    }\n    \n    /// <summary>\n    /// Create a readonly span of this array.  This doesn't do any copying, so it is very fast.   \n    /// </summary>\n    /// <param name=\"start\">Offset from the beginning of the array</param>\n    /// <param name=\"count\">The number of items to take. This will be clamped\n    /// to the maximum number of items available</param>\n    /// <returns>A read-only span of values</returns>\n    /// <exception cref=\"IndexOutOfRangeException\">Thrown If the start index is outside the range of the array</exception>\n    [Pure]\n    [MethodImpl(MethodImplOptions.AggressiveInlining)]\n    public ReadOnlySpan<A> AsSpan() =>","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/Arr/Arr.cs#L76-L112","documentation":"The internal Arr slice constructor validates the window bounds into the backing array: start must be >= 0 and start + length must not exceed value.Length, otherwise ArgumentOutOfRangeException is thrown. An Arr is a lightweight view (value, start, length) over an array, and invalid slicing parameters are rejected here.","triggerScenarios":"Constructing Arr via the internal (A[], int, int) ctor with a negative start, or a start+length combination exceeding the source array length (e.g. Skip/Take computed from wrong indices).","commonSituations":"Off-by-one errors in slicing logic, using a count from another collection that is longer than the source, or passing the original array length as start while also passing a positive length.","solutions":["Clamp arguments: Math.Max(0, start) and Math.Min(length, value.Length - start).","Fix the slice arithmetic (verify start/length derive from the same source array).","Use public Arr/Skip/Take APIs rather than the internal constructor so bounds are computed for you."],"exampleFix":"// before\nnew Arr<int>(data, data.Length, count);\n// after\nvar s = Math.Min(Math.Max(0, start), data.Length);\nnew Arr<int>(data, s, Math.Min(count, data.Length - s));","handlingStrategy":"validation","validationCode":"if (start < 0 || start + length > value.Length) throw new ArgumentOutOfRangeException(nameof(start));","typeGuard":"static bool ValidSlice<A>(A[] v, int start, int length) => start >= 0 && start + length <= v.Length;","tryCatchPattern":"try { var arr = new Arr<int>(data, start, len); } catch (ArgumentOutOfRangeException) { /* bad slice bounds */ }","preventionTips":["Clamp start and length against the array bounds","Use public slicing APIs instead of the internal ctor","Unit-test slice arithmetic for edge indices"],"tags":["arr","slice","argument-out-of-range","immutable-collections"],"backgroundTag":"argument-out-of-range","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}