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

  1. Add SectionName="name" or SectionId="@nonNullObject" to every SectionOutlet.
  2. If the identifier is dynamic, gate the outlet behind @if (identifier != null) so it never renders identifierless.
  3. 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

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


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