dotnet/aspnetcore · error · InvalidOperationException
SectionOutlet requires a non-null value either for 'SectionN
Error message
SectionOutlet requires a non-null value either for 'SectionName' or 'SectionId'.
What it means
SectionOutlet requires a target identifier to subscribe to the registry; with neither SectionName nor SectionId the Subscribe call cannot proceed and SetParametersAsync throws InvalidOperationException. An outlet with no subscription is meaningless, so this is a hard precondition rather than a soft default.
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 294cab2f9b)
Solutions
- Add SectionName="name" or SectionId="@nonNullObject" to every SectionOutlet.
- If the identifier is dynamic, gate the outlet behind @if (identifier != null) so it never renders identifierless.
- When constructing via RenderTreeBuilder, always AddAttribute for exactly one identifier before CloseComponent.
Example fix
// before
<SectionOutlet />
// after
<SectionOutlet SectionName="header" />
// or
@code { internal static readonly object HeaderId = new(); }
<SectionOutlet SectionId="@SectionIds.HeaderId" /> Defensive patterns
Strategy: validation
Validate before calling
@if (!string.IsNullOrEmpty(sectionName) || sectionId is not null)
{
<SectionOutlet SectionName="@sectionName" SectionId="@sectionId" />
} Type guard
static bool HasSectionIdentifier(string? name, object? id) =>
!string.IsNullOrEmpty(name) || id is not null; Prevention
- Always supply exactly one identifier to SectionOutlet.
- Gate data-driven outlets behind @if (id is not null).
- When building via RenderTreeBuilder, always AddAttribute one identifier.
When it happens
Trigger: Declaring a bare <SectionOutlet /> or binding both identifier parameters to nullable expressions that resolve to null. Hit on every SetParametersAsync where both are null.
Common situations: Forgot the identifier; conditional binding evaluates to null on first render; refactored markup and dropped the attribute; built the outlet via RenderTreeBuilder without supplying either parameter.
Related errors
- SectionOutlet requires that 'SectionName' and 'SectionId' ca
- SectionContent requires that 'SectionName' and 'SectionId' c
- SectionContent requires a non-null value either for 'Section
- Unknown parameter '{param.Name}'
- Unable to set property '{parameterName}' on object of type '
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/5cb452dd21eb15bd.
Report an issue: GitHub.