{"record":{"id":"e8b7e1a63fa5c62d","repo":"louthy/language-ext","slug":"invalidoperationexception","errorCode":null,"errorMessage":"InvalidOperationException","messagePattern":"InvalidOperationException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Immutable Collections/Seq/DSL/SeqConcat.cs","lineNumber":37,"sourceCode":"        Strict().AsSpan();\n\n    public A this[int index]\n    {\n        get\n        {\n            var r = At(index);\n            if (r.IsSome) return r.Value!;\n            throw new IndexOutOfRangeException();\n        }\n    }\n\n    public Option<A> At(int index)\n    {\n        if (index < 0) return default;\n        var ms1 = ms;\n        while (!ms1.IsEmpty)\n        {\n            var head = ms1.Head.ValueUnsafe() ?? throw new InvalidOperationException();\n            var r    = head.At(index);\n            if (r.IsSome) return r;\n            index -= head.Count;\n            ms1 = ms1.Tail;\n        }\n        return default;\n    }\n\n    public SeqType Type =>\n        SeqType.Concat;\n\n    public A Head \n    {\n        get \n        {\n            foreach (var s in ms)\n            {\n                foreach (var a in s)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Immutable Collections/Seq/DSL/SeqConcat.cs#L19-L55","documentation":"SeqConcat.At walks the list of concatenated segments and dereferences each head with ValueUnsafe(); when a segment's head Option is None (corrupt/empty internal segment) it throws InvalidOperationException. This is an internal invariant failure, not a user-input problem.","triggerScenarios":"Accessing elements of a Seq whose internal segment list contains an empty head — typically after misuse of low-level ISeqInternal APIs or a library bug, surfaced while calling At/indexing.","commonSituations":"Rare; usually indicates constructing a Seq from an empty ISeqInternal segment in custom DSL code or mixing internal Seq APIs (SeqStrict/SeqLazy/SeqConcat) incorrectly.","solutions":["Avoid constructing Seq from raw ISeqInternal segments; use public Seq/SeqStrict/SeqLazy constructors","Update LanguageExt — internal seq DSL invariants were fixed across versions","If hit inside custom DSL code, ensure every segment pushed to the concat list is non-empty","Catch InvalidOperationException defensively at iteration boundaries and rebuild the sequence"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (seq.IsEmpty || index < 0 || index >= seq.Count) return Option<A>.None;","typeGuard":null,"tryCatchPattern":"try { x = seq[index]; }\ncatch (InvalidOperationException)\n{ x = fallback; } // internal invariant failure; rebuild the sequence","preventionTips":["Avoid constructing Seq from raw ISeqInternal segments","Keep LanguageExt updated; the internal seq DSL had invariant fixes","Report recurring occurrences as a library bug"],"tags":["csharp","languageext","seq","internal-invariant"],"backgroundTag":"internal-invariant-violation","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"}