dotnet/aspnetcore · error · InvalidOperationException

{nameof(SectionOutlet)} requires that '{nameof(SectionName)}

Error message

{nameof(SectionOutlet)} requires that '{nameof(SectionName)}' and '{nameof(SectionId)}' cannot both have non-null values.

What it means

SectionOutlet — the consumer side of Blazor sections — identifies the section it renders by either SectionName (string) or SectionId (object), but never both. Setting both at parameter-set time is ambiguous: the outlet can only subscribe to one registry key, so SetParametersAsync throws InvalidOperationException before touching the registry. The check mirrors the one on 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 3600ca084e)

Solutions

  1. Choose one identifier style and remove the other attribute from <SectionOutlet>.
  2. Keep the SectionOutlet identifier consistent with the corresponding SectionContent (both name-based or both id-based).
  3. Use a shared constant or object instance to guarantee the pair matches.

Example fix

// before
<SectionOutlet SectionName="alerts" SectionId="@alertsId" />
// after
<SectionOutlet SectionName="alerts" />
Defensive patterns

Strategy: validation

Validate before calling

if (sectionName is not null && sectionId is not null)
    throw new InvalidOperationException("Set SectionName XOR SectionId, not both.");

Type guard

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

Prevention

When it happens

Trigger: Setting both SectionName="foo" and SectionId="@someObject" on the same <SectionOutlet> element.

Common situations: Switching identification styles and leaving both attributes in markup; copy-pasting between samples; auto-completion adding the second attribute.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/6063335d2c1fe03e. Report an issue: GitHub.