louthy/language-ext · error · NotSupportedException

NotSupportedException

Error message

NotSupportedException

What it means

Seq.Concat throws NotSupportedException when the internal optimization to merge two concatenated sequence representations does not apply — specifically when neither side's underlying SeqType matches a case the switch handles (e.g. an unexpected underlying value type). It signals an unhandled internal sequence-type combination in the Concat fast-path.

Solutions

  1. Update LanguageExt — this is an internal optimization gap that may be fixed in newer versions
  2. Work around by forcing a common representation before concatenating, e.g. seqA.ToSeq().Concat(seqB.ToSeq()) or building via Seq(a) literals
  3. Avoid Concat on exotic internal states: use Append/Add in a loop or IEnumerable composition (items1.Concat(items2).ToSeq())
  4. If reproducible, file a bug with the sequence construction steps

Example fix

// before
var all = hugeSeq.Concat(otherSeq); // NotSupportedException on internal type
// after
var all = hugeSeq.ToEnumerable().Concat(otherSeq.ToEnumerable()).ToSeq();
Defensive patterns

Strategy: try-catch

Try / catch

Seq<A> all;
try { all = a.Concat(b); }
catch (NotSupportedException) { all = a.ToEnumerable().Concat(b.ToEnumerable()).ToSeq(); }

Prevention

When it happens

Trigger: Calling seqA.Concat(seqB) where one operand's internal value is a SeqType not covered by the switch (not item-yield or concat types), or where the cast to SeqConcat<A> inside the Concat case is invalid for that combination.

Common situations: Mixing sequences created through different construction paths (lazily built vs. from arrays vs. previously concatenated) and hitting a code path not covered by the internal switch; usually indicates a library-level gap rather than caller misuse.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of louthy/language-ext@2f0e362824 (2026-09-15). Data as JSON: /api/errors/073c5f7f0ae5cb0d. Report an issue: GitHub.

Appendix: source

Thrown at LanguageExt.Core/Immutable Collections/Seq/Seq.cs:386

                    // lhs concat, rhs empty
                    // return lhs
                    case SeqType.Empty:
                        return this;

                    // lhs concat, rhs lazy || lhs concat, rhs strict
                    // add rhs to concat
                    case SeqType.Lazy:
                    case SeqType.Strict:
                        return new Seq<A>(((SeqConcat<A>)value).AddSeq(rhs.value));

                    // lhs concat, rhs concat
                    // add rhs to concat
                    case SeqType.Concat:
                        return new Seq<A>(((SeqConcat<A>)value).AddSeqRange(((SeqConcat<A>)rhs.value).ms));
                }
                break;
        }
        throw new NotSupportedException();
    }

    /// <summary>
    /// Prepend an item to the sequence
    /// </summary>
    [Pure]
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    internal Seq<A> Cons(A value) =>
        new (Value.Cons(value));

    /// <summary>
    /// Head item in the sequence.
    /// </summary>
    /// <remarks>
    /// If `IsEmpty` is `true` then Head is undefined and therefore returns `None`
    /// </remarks>
    public Option<A> Head
    {

View on GitHub (pinned to 2f0e362824)