dotnet/aspnetcore · error · InvalidOperationException

SectionOutlet requires that 'SectionName' and 'SectionId' ca

Error message

SectionOutlet requires that 'SectionName' and 'SectionId' cannot both have non-null values.

What it means

SectionOutlet is the consumer side of Blazor's section mechanism; it subscribes to content by exactly one of SectionName (string) or SectionId (object). SetParametersAsync throws InvalidOperationException when both are supplied because the subscription target would be ambiguous. SectionOutlet uses parameters.SetParameterProperties(this) then runs the same mutual-exclusion check as SectionContent.

Source

Thrown at src/Components/Components/src/Sections/SectionOutlet.cs:50

    internal IComponent? CurrentLogicalParent => _currentContentProvider;

    void IComponent.Attach(RenderHandle renderHandle)
    {
        _renderHandle = renderHandle;
        SectionRenderMode = renderHandle.RenderMode;
        _registry = _renderHandle.SectionRegistry;
    }

    Task IComponent.SetParametersAsync(ParameterView parameters)
    {
        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)
            {

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Keep only one identifier attribute on the SectionOutlet.
  2. Pick a single identifier convention for your app (string SectionName for simple cases, object SectionId for type-safe shared constants) and enforce it.
  3. If splatting attributes, ensure the dictionary contains exactly one of the two keys.

Example fix

// before
<SectionOutlet SectionName="header" SectionId="@HeaderId" />

// after
<SectionOutlet SectionId="@HeaderId" />
@code { private readonly object HeaderId = new(); }
Defensive patterns

Strategy: validation

Validate before calling

@if (!string.IsNullOrEmpty(sectionName) ^ sectionId is not null)
{
    <SectionOutlet SectionName="@sectionName" SectionId="@sectionId" />
}

Type guard

static bool HasSingleSectionIdentifier(string? name, object? id) =>
    (name is not null) ^ (id is not null);

Prevention

When it happens

Trigger: Declaring <SectionOutlet SectionName="header" SectionId="@id"> in markup, or splatting a parameter dictionary containing both keys. The check at SectionOutlet.cs:48 runs on every SetParametersAsync.

Common situations: Both attributes set during a refactor from string to object identifiers; copy-paste of an outlet template; a parent passing both via a splatted attribute dictionary.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/bb156ff5b54d26a8. Report an issue: GitHub.