dotnet/aspnetcore · error · ArgumentException

Unknown parameter '{param.Name}'

Error message

Unknown parameter '{param.Name}'

What it means

SectionContent.SetParameterValues manually switches on known parameter names (SectionName, SectionId, IsDefaultContent, ChildContent) instead of using ParameterView.SetParameterProperties. The default branch throws ArgumentException for any unrecognized name. Unlike the framework's automatic parameter binder, this strict switch gives no tolerance for typos or casing differences.

Source

Thrown at src/Components/Components/src/Sections/SectionContent.cs:107

    {
        foreach (var param in parameters)
        {
            switch (param.Name)
            {
                case nameof(SectionContent.SectionName):
                    SectionName = (string)param.Value;
                    break;
                case nameof(SectionContent.SectionId):
                    SectionId = param.Value;
                    break;
                case nameof(SectionContent.IsDefaultContent):
                    IsDefaultContent = (bool)param.Value;
                    break;
                case nameof(SectionContent.ChildContent):
                    ChildContent = (RenderFragment)param.Value;
                    break;
                default:
                    throw new ArgumentException($"Unknown parameter '{param.Name}'");
            }
        }
    }

    /// <inheritdoc/>
    public void Dispose()
    {
        if (_registeredIdentifier is not null)
        {
            _registry.RemoveProvider(_registeredIdentifier, this);
        }
    }
}

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Correct the attribute name to one of: SectionName, SectionId, or ChildContent (IsDefaultContent is internal and set by the framework).
  2. Match casing exactly — Razor is case-sensitive for these switch keys.
  3. Inspect any splatted dictionary passed via @attributes and remove keys that are not valid SectionContent parameters.
  4. Avoid passing IsDefaultContent from markup; default content is configured via the framework's SectionOutlet default-content API, not user parameters.

Example fix

// before
<SectionContent Section="header" ChildContent="@frag">
</SectionContent>

// after
<SectionContent SectionName="header">
    @frag
</SectionContent>
Defensive patterns

Strategy: validation

Validate before calling

// Whitelist SectionContent attributes before splatting
var allowed = new HashSet<string>(StringComparer.Ordinal)
{
    nameof(SectionContent.SectionName),
    nameof(SectionContent.SectionId),
    nameof(SectionContent.ChildContent)
};
foreach (var key in attributes.Keys.ToList())
    if (!allowed.Contains(key)) attributes.Remove(key);

Type guard

static bool IsValidSectionContentParam(string name) =>
    name is nameof(SectionContent.SectionName)
         or nameof(SectionContent.SectionId)
         or nameof(SectionContent.ChildContent);

Prevention

When it happens

Trigger: Passing an unknown attribute in markup, e.g. <SectionContent Section="header"> (misspelled as 'Section' instead of 'SectionName'), or splatting a dictionary whose keys include an extra entry. The strict switch fires on the first unknown parameter encountered during iteration.

Common situations: Typo in the attribute name (Section vs SectionName, Id vs SectionId); copy-paste from a SectionOutlet that uses different parameter casing; a splatted dictionary carrying stale keys; attempting to pass IsDefaultContent from user markup (it is internal-only).

Related errors


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