Unity-Technologies/UnityCsReference · error · ArgumentException

Duplicate column indices are not allowed

Error message

Duplicate column indices are not allowed

What it means

Thrown by SetSortingColumns when columnIndices contains duplicate values. Sorting by the same column twice is meaningless and would produce ambiguous sort order, so duplicates are rejected.

Source

Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeader.cs:84

            m_HeaderButtonsControlID = GUIUtility.GetPermanentControlID();
        }

        public void SetSortingColumns(int[] columnIndices, bool[] sortAscending)
        {
            if (columnIndices == null)
                throw new ArgumentNullException("columnIndices");

            if (sortAscending == null)
                throw new ArgumentNullException("sortAscending");

            if (columnIndices.Length != sortAscending.Length)
                throw new ArgumentException("Input arrays should have same length");

            if (columnIndices.Length > state.maximumNumberOfSortedColumns)
                throw new ArgumentException("The maximum number of sorted columns is " + state.maximumNumberOfSortedColumns + ". Trying to set " + columnIndices.Length + " columns.");

            if (columnIndices.Length != columnIndices.DistinctCount())
                throw new ArgumentException("Duplicate column indices are not allowed", "columnIndices");

            bool changed = false;

            if (!columnIndices.AsSpan().SequenceEqual(state.sortedColumns))
            {
                state.sortedColumns = columnIndices;
                changed = true;
            }

            for (int i = 0; i < columnIndices.Length; ++i)
            {
                var column = GetColumn(columnIndices[i]);
                if (column.sortedAscending != sortAscending[i])
                {
                    column.sortedAscending = sortAscending[i];
                    changed = true;
                }
            }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Deduplicate columnIndices preserving order before calling (e.g. Distinct()).
  2. Validate columnIndices.DistinctCount() == columnIndices.Length as a precondition.
  3. Fix the upstream source that introduced the duplicate.

Example fix

// before
header.SetSortingColumns(cols, flags); // cols has dupes

// after
var deduped = cols.Distinct().ToArray();
header.SetSortingColumns(deduped, flags.Take(deduped.Length).ToArray());
Defensive patterns

Strategy: validation

Validate before calling

var distinct = columnIndices.Distinct().ToArray(); if (distinct.Length != columnIndices.Length) { /* handle duplicate */ }

Prevention

When it happens

Trigger: Passing an array like {0, 0, 1}; merging sort lists from multiple sources without deduplication.

Common situations: Aggregating user sort selections across UI panels without dedup; restored state from a buggy serializer that duplicated entries.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/3f6358a0575872e6. Report an issue: GitHub.