{"record":{"id":"1e362ca2af8c1568","repo":"dotnet/aspnetcore","slug":"sectioncontent-requires-a-non-null-value-either-fo","errorCode":null,"errorMessage":"SectionContent requires a non-null value either for 'SectionName' or 'SectionId'.","messagePattern":"SectionContent requires a non-null value either for 'SectionName' or 'SectionId'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Sections/SectionContent.cs","lineNumber":68,"sourceCode":"        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            {\n                _registry.RemoveProvider(_registeredIdentifier, this);\n            }\n\n            _registry.AddProvider(identifier, this, IsDefaultContent);\n            _registeredIdentifier = identifier;\n            _registeredIsDefaultContent = IsDefaultContent;\n        }\n\n        _registry.NotifyContentProviderChanged(identifier, this);\n\n        return Task.CompletedTask;\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Sections/SectionContent.cs#L50-L86","documentation":"SectionContent must target an outlet; if neither SectionName nor SectionId is supplied, SetParametersAsync throws InvalidOperationException because there is no identifier to register with the SectionRegistry. The component has no default-free mode — it always needs a target. Without an identifier the registry cannot AddProvider, so this guards against a silently unregistered provider.","triggerScenarios":"Declaring <SectionContent> with only ChildContent and no SectionName/SectionId, or dynamically rendering a SectionContent whose identifier parameters are both conditionally null. Hit whenever SetParametersAsync runs and both identifier parameters are null.","commonSituations":"Forgot to add the identifier attribute; bound the identifier to a nullable expression that evaluates to null at first render; refactored markup and dropped the SectionName attribute.","solutions":["Add SectionName=\"some-name\" or SectionId=\"@someNonNullOrootObject\" to every <SectionContent> usage.","If the identifier is data-driven, ensure it is non-null before the component renders, or wrap the SectionContent in an @if block that gates on the identifier.","Grep the markup for '<SectionContent' occurrences missing both SectionName and SectionId."],"exampleFix":"// before\n<SectionContent>\n    <Header />\n</SectionContent>\n\n// after\n<SectionContent SectionName=\"header\">\n    <Header />\n</SectionContent>","handlingStrategy":"validation","validationCode":"// Render SectionContent only when an identifier exists\n@if (!string.IsNullOrEmpty(sectionName) || sectionId is not null)\n{\n    <SectionContent SectionName=\"@sectionName\" SectionId=\"@sectionId\">\n        @ChildContent\n    </SectionContent>\n}","typeGuard":"static bool HasSectionIdentifier(string? name, object? id) =>\n    !string.IsNullOrEmpty(name) || id is not null;","tryCatchPattern":null,"preventionTips":["Make identifier parameters required by convention (always pass at least one).","If identifiers are data-driven, gate the SectionContent behind @if (id is not null).","Review any dynamically built RenderFragment that constructs a SectionContent."],"tags":["blazor","sections","sectioncontent","parameters","invalidoperationexception"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}