louthy/language-ext · error · NotSupportedException

NotSupportedException

Error message

NotSupportedException

What it means

SeqConcat.Add appends a value to the LAST segment; if the segment list is empty (or its last segment is null) there is nowhere to add, so it throws NotSupportedException. This DSL node only supports Add when it contains at least one segment.

Solutions

  1. Ensure the SeqConcat is initialized with a non-empty segment (e.g. a SeqStrict) before Add
  2. Use Cons to start a new value at the head instead, or rebuild the seq from scratch
  3. Update LanguageExt — newer versions hardened the internal seq DSL

Example fix

// before
var concat = new SeqConcat<A>(SeqEmptyInternal.Default);
concat.Add(value); // NotSupportedException
// after
var concat = new SeqConcat<A>(new SeqStrict<A>(value, SeqEmptyInternal.Default));
var next = concat.Add(value); // OK
Defensive patterns

Strategy: validation

Validate before calling

if (seq.IsEmpty) seq = Seq(value); else seq = seq.Add(value); // public-level equivalent guard

Try / catch

try { seq = concat.Add(value); }
catch (NotSupportedException)
{ seq = new SeqStrict<A>(value, SeqEmptyInternal.Default); }

Prevention

When it happens

Trigger: Calling Add (via seq insertion APIs) on a SeqConcat whose ms segment list is empty — e.g. after constructing it with an empty sequence of segments.

Common situations: Custom Seq-building code that creates a SeqConcat without an initial non-empty segment; incremental building that started from an empty concat node.

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/7f74231c943c4a8f. Report an issue: GitHub.

Appendix: source

Thrown at LanguageExt.Core/Immutable Collections/Seq/DSL/SeqConcat.cs:110

            throw Exceptions.SequenceEmpty;
        }
    }

    public int Count => 
        ms.Sum(s => s.Count);

    public SeqConcat<A> AddSeq(ISeqInternal<A> ma) =>
        new (ms.Add(ma));

    public SeqConcat<A> AddSeqRange(Seq<ISeqInternal<A>> ma) =>
        new (ms.Concat(ma));

    public SeqConcat<A> ConsSeq(ISeqInternal<A> ma) =>
        new (ma.Cons(ms));

    public ISeqInternal<A> Add(A value)
    {
        var last = ms.Last.ValueUnsafe()?.Add(value) ?? throw new NotSupportedException();
        return new SeqConcat<A>(ms.Take(ms.Count - 1).Add(last));
    }

    public ISeqInternal<A> Cons(A value)
    {
        var head = ms.Head.ValueUnsafe()?.Cons(value) ?? throw new NotSupportedException();
        return new SeqConcat<A>(head.Cons(ms.Skip(1)));
    }

    public bool Exists(Func<A, bool> f) =>
        ms.Exists(s => s.Exists(f));
        
    public S Fold<S>(S state, Func<S, A, S> f) =>
        ms.Fold(state, (s, x) => x.Fold(s, f));

    public S FoldBack<S>(S state, Func<S, A, S> f) =>
        ms.FoldBack(state, (s, x) => x.FoldBack(s, f));

View on GitHub (pinned to 2f0e362824)