Unity-Technologies/UnityCsReference · error · ArgumentNullException

sortAscending

Error message

sortAscending

What it means

Thrown by MultiColumnHeader.SetSortingColumns when the sortAscending boolean array is null. Each column index must have a corresponding ascending/descending flag, so a null flags array is rejected.

Source

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

                if (value == null)
                    throw new ArgumentNullException("state", "MultiColumnHeader state is not allowed to be null");
                m_State = value;
            }
        }

        public MultiColumnHeader(MultiColumnHeaderState state)
        {
            m_State = state;
            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;
            }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Construct a boolean array matching the length of columnIndices (e.g. all true for ascending).
  2. Use 'Array.Empty<bool>()' when columnIndices is also empty.
  3. Generate the flags from a sort definition before calling.

Example fix

// before
header.SetSortingColumns(cols, null);

// after
bool[] ascending = cols.Select(c => true).ToArray();
header.SetSortingColumns(cols, ascending);
Defensive patterns

Strategy: validation

Validate before calling

bool[] asc = (sortAscending ?? new bool[columnIndices.Length]).ToArray(); if (asc.Length != columnIndices.Length) asc = columnIndices.Select(_ => true).ToArray();

Type guard

static bool IsValidFlagsArray(bool[] a, int expected) => a != null && a.Length == expected;

Prevention

When it happens

Trigger: Calling SetSortingColumns(columnIndices, null); providing column indices but omitting the sort directions.

Common situations: Forgetting to build the parallel boolean array; a default-ascending shortcut that passes null intending 'all ascending'.

Related errors


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