dotnet/aspnetcore · error · InvalidOperationException
{nameof(SectionContent)} requires a non-null value either fo
Error message
{nameof(SectionContent)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'. What it means
SectionContent must be associated with at least one identifier — either a SectionName string or a SectionId object — so the registry knows which SectionOutlet to feed. If both are null, the component has no key under which to register itself and throws InvalidOperationException. This is the symmetric counterpart to the both-set check.
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 3600ca084e)
Solutions
- Add either SectionName="<name>" or SectionId="@<object>" to the <SectionContent> element.
- If binding SectionName to an expression, ensure it is never null at render time (provide a default or guard the render with @if).
- Use a constant for shared section names to avoid typos that produce null bindings.
Example fix
// before
<SectionContent>
<p>Will never show</p>
</SectionContent>
// after
<SectionContent SectionName="alerts">
<p>Visible where <SectionOutlet SectionName="alerts" /> lives</p>
</SectionContent> Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(sectionName) && sectionId is null)
throw new InvalidOperationException("SectionContent 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 <SectionContent>.
- Guard dynamic bindings: @if (!string.IsNullOrEmpty(name)) { <SectionContent SectionName=@name>...</SectionContent> }.
- Keep SectionContent identifiers paired with matching SectionOutlet identifiers.
When it happens
Trigger: Declaring <SectionContent>...</SectionContent> with neither SectionName nor SectionId set. The component has no other default identifier.
Common situations: Adding a SectionContent and forgetting to specify the target; refactoring markup and dropping the identifier attribute; binding SectionName to an expression that evaluates to null at runtime.
Related errors
- {nameof(SectionContent)} requires that '{nameof(SectionName)
- {nameof(SectionOutlet)} requires that '{nameof(SectionName)}
- {nameof(SectionOutlet)} requires a non-null value either for
- 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/e1e434527972f38f.
Report an issue: GitHub.