{"record":{"id":"2b7b843be8b813d4","repo":"dotnet/aspnetcore","slug":"sectioncontent-requires-that-sectionname-and-se","errorCode":null,"errorMessage":"SectionContent requires that 'SectionName' and 'SectionId' cannot both have non-null values.","messagePattern":"SectionContent requires that 'SectionName' and 'SectionId' cannot both have non-null values\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Sections/SectionContent.cs","lineNumber":56,"sourceCode":"    [Parameter] public RenderFragment? ChildContent { get; set; }\n\n    void IComponent.Attach(RenderHandle renderHandle)\n    {\n        SectionRenderMode = renderHandle.RenderMode;\n        _registry = renderHandle.SectionRegistry;\n    }\n\n    Task IComponent.SetParametersAsync(ParameterView parameters)\n    {\n        // We are not using parameters.SetParameterProperties(this)\n        // because IsDefaultContent is internal property and not a parameter\n        SetParameterValues(parameters);\n\n        object? identifier;\n\n        if (SectionName is not null && SectionId is not null)\n        {\n            throw new InvalidOperationException($\"{nameof(SectionContent)} requires that '{nameof(SectionName)}' and '{nameof(SectionId)}' cannot both have non-null values.\");\n        }\n        else if (SectionName is not null)\n        {\n            identifier = SectionName;\n        }\n        else if (SectionId is not null)\n        {\n            identifier = SectionId;\n        }\n        else\n        {\n            throw new InvalidOperationException($\"{nameof(SectionContent)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'.\");\n        }\n\n        if (!object.Equals(identifier, _registeredIdentifier) || IsDefaultContent != _registeredIsDefaultContent)\n        {\n            if (_registeredIdentifier is not null)\n            {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Sections/SectionContent.cs#L38-L74","documentation":"SectionContent is the provider side of Blazor's content-sharing mechanism; it identifies its target outlet by exactly one of SectionName (string) or SectionId (object). SetParametersAsync throws InvalidOperationException when both are non-null because the matching identifier is ambiguous. This is an invariant enforced on every parameter set, so it fires even if the two values would resolve to the same outlet.","triggerScenarios":"Declaring <SectionContent SectionName=\"header\" SectionId=\"@someObj\"> in markup, or programmatically passing both parameters when constructing the component. The check at SectionContent.cs:54 is hit on the first SetParametersAsync call and on every subsequent re-render that supplies both values.","commonSituations":"Copy-pasting a SectionContent and forgetting to remove one identifier; migrating from SectionName (string) to SectionId (object) and leaving the old attribute; a parent component passing both via splatting dictionaries.","solutions":["Remove one of the two attributes so only SectionName OR SectionId is set.","If migrating identifiers, delete the stale attribute rather than commenting it out — Razor still binds commented-style typos in code blocks.","Audit any splatted ParameterView/Dictionary<string,object> passed to SectionContent to ensure it does not contain both keys.","Use SectionId with a static object instance (e.g., a readonly field) when you need compile-time uniqueness instead of the string key."],"exampleFix":"// before\n<SectionContent SectionName=\"header\" SectionId=\"@MyHeaderId\">\n    <Header />\n</SectionContent>\n\n// after\n<SectionContent SectionId=\"@MyHeaderId\">\n    <Header />\n</SectionContent>","handlingStrategy":"validation","validationCode":"// Validate before rendering the SectionContent\n@if (!string.IsNullOrEmpty(sectionName) ^ sectionId is not null)\n{\n    <SectionContent SectionName=\"@sectionName\" SectionId=\"@sectionId\">\n        @ChildContent\n    </SectionContent>\n}\nelse\n{\n    <div class=\"alert alert-danger\">SectionContent needs exactly one identifier.</div>\n}","typeGuard":"// Exactly one identifier must be set\nstatic bool HasSingleSectionIdentifier(string? name, object? id) =>\n    (name is not null) ^ (id is not null);","tryCatchPattern":"// Razor cannot easily catch render-time exceptions; instead gate the component.\n// If rendering imperatively via RenderTreeBuilder, validate first:\nobject? identifier = sectionName ?? sectionId;\nif (HasSingleSectionIdentifier(sectionName, sectionId))\n{\n    builder.OpenComponent<SectionContent>(0);\n    if (sectionName is not null) builder.AddAttribute(1, \"SectionName\", sectionName);\n    if (sectionId is not null) builder.AddAttribute(2, \"SectionId\", sectionId);\n    builder.CloseComponent();\n}","preventionTips":["Adopt one identifier convention per app (SectionName for simple, SectionId for type-safe) and lint against the other.","Never splat attribute dictionaries into SectionContent without filtering keys.","Add a unit test asserting every SectionContent usage sets exactly one identifier."],"tags":["blazor","sections","sectioncontent","parameters","invalidoperationexception"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}