Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid list: cannot be null
Error message
Invalid list: cannot be null
What it means
Thrown by TreeViewControlDataSource.SearchFullTree when the result list argument is null. The method writes matching items into the provided list; a null list has no capacity to receive results.
Source
Thrown at Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs:77
}
// Rows
m_Rows = m_Owner.BuildRows(m_RootItem);
if (m_Rows == null)
throw new NullReferenceException("RefreshRows should set valid list of rows.");
// Custom row rects
if (m_Owner.m_OverriddenMethods.hasGetCustomRowHeight)
m_Owner.m_GUI.RefreshRowRects(m_Rows);
}
public void SearchFullTree(string search, List<TreeViewItem<TIdentifier>> result)
{
if (string.IsNullOrEmpty(search))
throw new ArgumentException("Invalid search: cannot be null or empty", "search");
if (result == null)
throw new ArgumentException("Invalid list: cannot be null", "result");
var stack = new Stack<TreeViewItem<TIdentifier>>();
stack.Push(m_RootItem);
while (stack.Count > 0)
{
TreeViewItem<TIdentifier> current = stack.Pop();
if (current.children != null)
{
foreach (var child in current.children)
{
if (child != null)
{
if (m_Owner.DoesItemMatchSearch(child, search))
result.Add(child);
stack.Push(child);
}
}View on GitHub (pinned to 225b0fbdb5)
Solutions
- Allocate the results list before calling: var results = new List<TreeViewItem<TIdentifier>>();
- Initialize the cached results field at declaration or in OnEnable.
- Add a null guard that allocates on demand.
Example fix
// before dataSource.SearchFullTree(search, m_Results); // m_Results is null // after m_Results = m_Results ?? new List<TreeViewItem<TIdentifier>>(); dataSource.SearchFullTree(search, m_Results);
Defensive patterns
Strategy: validation
Validate before calling
result = result ?? new List<TreeViewItem<TIdentifier>>(); dataSource.SearchFullTree(search, result);
Prevention
- Allocate the result list before calling SearchFullTree.
- Initialize list fields at declaration.
- Never pass null as an output collection.
When it happens
Trigger: Calling SearchFullTree(search, null); passing a list field that was never initialized; a prior code path setting the result reference to null.
Common situations: Custom search invocation that forgets to allocate the results list; refactoring that moved allocation after the call.
Related errors
- Invalid list: cannot be null
- Invalid TreeViewState: it is null
- root is null
- rows is null
- Invalid search: cannot be null or empty
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/772d05cccbb9efc9.
Report an issue: GitHub.