Unity-Technologies/UnityCsReference · error · ArgumentException
columns are no allowed to be null
Error message
columns are no allowed to be null
What it means
Thrown by the MultiColumnHeaderState constructor when the columns array argument is null. A header state with no column definitions cannot render or sort anything, so null is rejected at construction.
Source
Thrown at Editor/Mono/GUI/TreeView/MultiColumnHeaderState.cs:75
return;
}
#pragma warning disable UA2001 // The Banned API Analyzer produces compile errors for any new Linq code. This pre-existing usage has been suppressed, but should be rewritten if possible.
destination.m_VisibleColumns = source.m_VisibleColumns.ToArray();
#pragma warning restore UA2001
destination.m_SortedColumns = new List<int>(source.m_SortedColumns);
for (int i = 0; i < destination.m_Columns.Length; ++i)
{
destination.m_Columns[i].width = source.m_Columns[i].width;
destination.m_Columns[i].sortedAscending = source.m_Columns[i].sortedAscending;
}
}
public MultiColumnHeaderState(Column[] columns)
{
if (columns == null)
throw new ArgumentException("columns are no allowed to be null", "columns");
if (columns.Length == 0)
throw new ArgumentException("columns array should at least have one column: it is empty", "columns");
m_Columns = columns;
m_SortedColumns = new List<int>();
// Default to all visible
m_VisibleColumns = new int[m_Columns.Length];
for (int i = 0; i < m_Columns.Length; ++i)
m_VisibleColumns[i] = i;
}
public int sortedColumnIndex
{
get
{
return m_SortedColumns.Count > 0 ? m_SortedColumns[0] : -1;
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Always pass a non-null Column[]; use an empty-safe builder that guarantees at least one column.
- If no columns are applicable, avoid constructing the state at all rather than passing null.
- Null-coalesce at the call site: columns ?? throw new InvalidOperationException("no columns defined").
Example fix
// before
var st = new MultiColumnHeaderState(BuildColumns()); // may be null
// after
Column[] cols = BuildColumns() ?? throw new InvalidOperationException("No columns defined");
var st = new MultiColumnHeaderState(cols); Defensive patterns
Strategy: validation
Validate before calling
if (columns == null) throw new ArgumentNullException(nameof(columns)); // or supply defaults
Type guard
static bool HasColumns(Column[] c) => c != null && c.Length > 0;
Prevention
- Guarantee column builders return non-null arrays.
- Null-coalesce at the construction call site.
- Avoid constructing MultiColumnHeaderState when no columns exist.
When it happens
Trigger: Constructing 'new MultiColumnHeaderState(null)'; passing a column-builder method that returned null on failure.
Common situations: Dynamic column generation that returns null when no columns are applicable; deserialization helpers that yield null for empty definitions.
Related errors
- MultiColumnHeader state is not allowed to be null
- columnIndices
- sortAscending
- visibleColumns should not be set to null
- Input arrays should have same length
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/a5383ebd1687aaa2.
Report an issue: GitHub.