dotnet/aspnetcore · error · InvalidOperationException
SectionContent requires a non-null value either for 'Section
Error message
SectionContent requires a non-null value either for 'SectionName' or 'SectionId'.
What it means
SectionContent must target an outlet; if neither SectionName nor SectionId is supplied, SetParametersAsync throws InvalidOperationException because there is no identifier to register with the SectionRegistry. The component has no default-free mode — it always needs a target. Without an identifier the registry cannot AddProvider, so this guards against a silently unregistered provider.
Source
Thrown at src/Components/Components/src/Sections/SectionContent.cs:68
SetParameterValues(parameters);
object? identifier;
if (SectionName is not null && SectionId is not null)
{
throw new InvalidOperationException($"{nameof(SectionContent)} 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(SectionContent)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'.");
}
if (!object.Equals(identifier, _registeredIdentifier) || IsDefaultContent != _registeredIsDefaultContent)
{
if (_registeredIdentifier is not null)
{
_registry.RemoveProvider(_registeredIdentifier, this);
}
_registry.AddProvider(identifier, this, IsDefaultContent);
_registeredIdentifier = identifier;
_registeredIsDefaultContent = IsDefaultContent;
}
_registry.NotifyContentProviderChanged(identifier, this);
return Task.CompletedTask;
}View on GitHub (pinned to 294cab2f9b)
Solutions
- Add SectionName="some-name" or SectionId="@someNonNullOrootObject" to every <SectionContent> usage.
- If the identifier is data-driven, ensure it is non-null before the component renders, or wrap the SectionContent in an @if block that gates on the identifier.
- Grep the markup for '<SectionContent' occurrences missing both SectionName and SectionId.
Example fix
// before
<SectionContent>
<Header />
</SectionContent>
// after
<SectionContent SectionName="header">
<Header />
</SectionContent> Defensive patterns
Strategy: validation
Validate before calling
// Render SectionContent only when an identifier exists
@if (!string.IsNullOrEmpty(sectionName) || sectionId is not null)
{
<SectionContent SectionName="@sectionName" SectionId="@sectionId">
@ChildContent
</SectionContent>
} Type guard
static bool HasSectionIdentifier(string? name, object? id) =>
!string.IsNullOrEmpty(name) || id is not null; Prevention
- Make identifier parameters required by convention (always pass at least one).
- If identifiers are data-driven, gate the SectionContent behind @if (id is not null).
- Review any dynamically built RenderFragment that constructs a SectionContent.
When it happens
Trigger: Declaring <SectionContent> with only ChildContent and no SectionName/SectionId, or dynamically rendering a SectionContent whose identifier parameters are both conditionally null. Hit whenever SetParametersAsync runs and both identifier parameters are null.
Common situations: Forgot to add the identifier attribute; bound the identifier to a nullable expression that evaluates to null at first render; refactored markup and dropped the SectionName attribute.
Related errors
- SectionContent requires that 'SectionName' and 'SectionId' c
- Unknown parameter '{param.Name}'
- SectionOutlet requires that 'SectionName' and 'SectionId' ca
- SectionOutlet requires a non-null value either for 'SectionN
- Unable to set property '{parameterName}' on object of type '
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/1e362ca2af8c1568.
Report an issue: GitHub.