dotnet/aspnetcore · error · InvalidOperationException
{nameof(SectionOutlet)} requires a non-null value either for
Error message
{nameof(SectionOutlet)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'. What it means
SectionOutlet requires at least one identifier so the registry knows which SectionContent providers to subscribe to. If both SectionName and SectionId are null the outlet has nothing to listen for, so SetParametersAsync throws InvalidOperationException before subscribing. This is the symmetric counterpart to the both-set check.
Source
Thrown at src/Components/Components/src/Sections/SectionOutlet.cs:62
parameters.SetParameterProperties(this);
object? identifier;
if (SectionName is not null && SectionId is not null)
{
throw new InvalidOperationException($"{nameof(SectionOutlet)} requires that '{nameof(SectionName)}' and '{nameof(SectionId)}' cannot both have non-null values.");
}
else if (SectionName is not null)
{
identifier = SectionName;
}
else if (SectionId is not null)
{
identifier = SectionId;
}
else
{
throw new InvalidOperationException($"{nameof(SectionOutlet)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'.");
}
if (!object.Equals(identifier, _subscribedIdentifier))
{
if (_subscribedIdentifier is not null)
{
_registry.Unsubscribe(_subscribedIdentifier);
}
_registry.Subscribe(identifier, this);
_subscribedIdentifier = identifier;
}
RenderContent();
return Task.CompletedTask;
}
View on GitHub (pinned to 3600ca084e)
Solutions
- Add either SectionName="<name>" or SectionId="@<object>" to the <SectionOutlet>.
- If binding SectionName dynamically, guard it so it is never null when the outlet renders, or wrap the outlet in @if (!string.IsNullOrEmpty(name)).
- Share a constant for section names so the outlet always matches the corresponding SectionContent.
Example fix
// before <SectionOutlet /> // after <SectionOutlet SectionName="alerts" />
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(sectionName) && sectionId is null)
throw new InvalidOperationException("SectionOutlet requires SectionName or SectionId."); Type guard
static bool HasSectionIdentifier(string? name, object? id)
=> !string.IsNullOrEmpty(name) || id is not null; Prevention
- Always set SectionName or SectionId on <SectionOutlet>.
- Guard dynamic bindings so the identifier is never null at render time.
- Pair each SectionOutlet with a matching SectionContent using a shared constant or object.
When it happens
Trigger: Declaring <SectionOutlet /> with neither SectionName nor SectionId set, or binding SectionName to an expression that evaluates to null.
Common situations: Adding a SectionOutlet and forgetting the identifier; refactoring markup and dropping the attribute; binding to a property that is conditionally null at render time.
Related errors
- {nameof(SectionOutlet)} requires that '{nameof(SectionName)}
- {nameof(SectionContent)} requires that '{nameof(SectionName)
- {nameof(SectionContent)} requires a non-null value either fo
- The {nameof(Router)} component requires a value for the para
- The {nameof(Router)} component requires a value for the para
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/d3081d862b3df646.
Report an issue: GitHub.