Unity-Technologies/UnityCsReference · error · ArgumentException
Invalid search: cannot be null or empty
Error message
Invalid search: cannot be null or empty
What it means
Thrown by TreeViewControlDataSource.SearchFullTree when the search string is null or empty. The method walks the tree pushing items onto a stack and filtering by the search term; an empty/null search would match everything and is treated as a misuse (callers should use the non-search row path instead).
Source
Thrown at Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControlDataSource.cs:74
{
m_RootItem = m_Owner.BuildRoot();
ValidateRootItem();
}
// 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);
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check string.IsNullOrEmpty(search) before calling SearchFullTree and use the normal row-building path instead.
- Only call SearchFullTree when the user has entered non-whitespace search text.
- Guard: if (string.IsNullOrWhiteSpace(search)) return;
Example fix
// before
dataSource.SearchFullTree(searchField, rows); // searchField could be empty
// after
if (!string.IsNullOrEmpty(searchField))
dataSource.SearchFullTree(searchField, rows);
else
AddExpandedRows(rootItem, rows); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(search))
dataSource.SearchFullTree(search, result);
else
AddExpandedRows(root, result); Type guard
static bool HasSearchText(string s) => !string.IsNullOrEmpty(s);
Prevention
- Check for null/empty search before calling SearchFullTree.
- Route empty searches to the normal row-building path.
- Guard against whitespace-only search as well.
When it happens
Trigger: Calling SearchFullTree(string.Empty, result); calling with a null search string; a search field that was cleared but SearchFullTree was still invoked.
Common situations: UI search box cleared by the user but the search method was called before checking the empty case; programmatic search with an uninitialized string.
Related errors
- visibleColumns should should not be set to an empty array. A
- Invalid list: cannot be null
- Invalid list: cannot be null
- Invalid argument: {dropPosition}
- The setting label can't be null or empty.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/be297d79c2418df4.
Report an issue: GitHub.