stride3d/stride · critical · Exception

SortedList::internal error (

Error message

SortedList::internal error (

What it means

PutImpl computes the insertion position as the bitwise complement of the binary-search result; if that position exceeds Capacity + 1, the internal table state is corrupt, so it throws a generic Exception starting with "SortedList::internal error". This signals a broken invariant rather than a caller mistake, thrown by the constructor and Add().

Solutions

  1. Treat it as a bug: report it to Stride with a repro (key, value, capacity, Count at failure).
  2. Rebuild the SortedList from source data instead of reusing the corrupted instance.
  3. Guard shared SortedList instances with locks or use concurrent collections if accessed from multiple threads.
  4. Check you are not mutating internal fields (table/keys/values) via reflection or unsafe serializers.

Example fix

// before
sharedList.Add(key, value); // unsynchronized across threads
// after
lock (syncRoot) { sharedList.Add(key, value); }
Defensive patterns

Strategy: fallback

Try / catch

try { sortedList.Add(key, value); }
catch (Exception ex) when (ex.Message.StartsWith("SortedList::internal error"))
{ sortedList = RebuildFromSource(); // recreate the collection from authoritative data }

Prevention

When it happens

Trigger: Practically only from memory corruption, a mutated internal table (e.g. via unsafe reflection/serialization tricks), or a genuine library bug in EnsureCapacity/binary-search bookkeeping during Add.

Common situations: Rare; typically encountered after custom serialization round-trips of the internal fields, concurrent modification without synchronization, or porting/patching the collection code.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f5bce487f622be4f. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core/Collections/SortedList.cs:548

        catch (Exception)
        {
            throw new InvalidOperationException();
        }

        if (freeIndx >= 0)
        {
            if (!overwrite)
                throw new ArgumentException("element already exists");

            table[freeIndx] = new KeyValuePair<TKey, TValue>(key, value);
            ++modificationCount;
            return;
        }

        freeIndx = ~freeIndx;

        if (freeIndx > Capacity + 1)
            throw new Exception("SortedList::internal error (" + key + ", " + value + ") at [" + freeIndx + "]");


        EnsureCapacity(Count + 1, freeIndx);

        table = this.table;
        table[freeIndx] = new KeyValuePair<TKey, TValue>(key, value);

        ++inUse;
        ++modificationCount;

    }

    private void Init(IComparer<TKey> comparer, int capacity, bool forceSize)
    {
        if (comparer == null)
            comparer = Comparer<TKey>.Default;
        this.comparer = comparer;
        if (!forceSize && (capacity < defaultCapacity))

View on GitHub (pinned to 96fad776d2)