AvaloniaUI/Avalonia · error · ArgumentException
Cannot add null to LogicalChildren.
Error message
Cannot add null to LogicalChildren.
What it means
Error "Cannot add null to LogicalChildren." thrown in AvaloniaUI/Avalonia.
Source
Thrown at src/Avalonia.Base/StyledElement.cs:758
{
while (e != null)
{
if (e is ILogicalRoot root)
{
return root;
}
e = e.StylingParent;
}
return null;
}
void IAvaloniaListItemValidator<ILogical>.Validate(ILogical item)
{
if (item is null)
{
throw new ArgumentException($"Cannot add null to {nameof(LogicalChildren)}.");
}
}
private void ApplyControlTheme()
{
if (GetEffectiveTheme() is { } theme)
ApplyControlTheme(theme, FrameType.Theme);
}
private void ApplyTemplatedParentControlTheme()
{
if ((TemplatedParent as StyledElement)?.GetEffectiveTheme() is { } parentTheme)
{
ApplyControlTheme(parentTheme, FrameType.TemplatedParentTheme);
}
}
private void ApplyControlTheme(ControlTheme theme, FrameType type)View on GitHub (pinned to 11c5427268)
Solutions
- Ensure the object added to LogicalChildren is not null; guard the Add call with a null check.
- Fix the code path that produces a null child (e.g. a converter or template lookup returning null).
When it happens
Trigger: Raised when null is added to a LogicalChildren collection. Defend by null-checking child elements before adding them and filtering nulls from computed child sequences.
Common situations: See trigger scenarios.
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/025a43d5d5f12f5c.
Report an issue: GitHub.