{"record":{"id":"d3081d862b3df646","repo":"dotnet/aspnetcore","slug":"nameof-sectionoutlet-requires-a-non-null-value","errorCode":null,"errorMessage":"{nameof(SectionOutlet)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'.","messagePattern":"(.+?) requires a non-null value either for '(.+?)' or '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Sections/SectionOutlet.cs","lineNumber":62,"sourceCode":"        parameters.SetParameterProperties(this);\n\n        object? identifier;\n\n        if (SectionName is not null && SectionId is not null)\n        {\n            throw new InvalidOperationException($\"{nameof(SectionOutlet)} 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(SectionOutlet)} requires a non-null value either for '{nameof(SectionName)}' or '{nameof(SectionId)}'.\");\n        }\n\n        if (!object.Equals(identifier, _subscribedIdentifier))\n        {\n            if (_subscribedIdentifier is not null)\n            {\n                _registry.Unsubscribe(_subscribedIdentifier);\n            }\n\n            _registry.Subscribe(identifier, this);\n            _subscribedIdentifier = identifier;\n        }\n\n        RenderContent();\n\n        return Task.CompletedTask;\n    }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/Sections/SectionOutlet.cs#L44-L80","documentation":"SectionOutlet requires at least one identifier so the registry knows which SectionContent providers to subscribe to. If both SectionName and SectionId are null the outlet has nothing to listen for, so SetParametersAsync throws InvalidOperationException before subscribing. This is the symmetric counterpart to the both-set check.","triggerScenarios":"Declaring <SectionOutlet /> with neither SectionName nor SectionId set, or binding SectionName to an expression that evaluates to null.","commonSituations":"Adding a SectionOutlet and forgetting the identifier; refactoring markup and dropping the attribute; binding to a property that is conditionally null at render time.","solutions":["Add either SectionName=\"<name>\" or SectionId=\"@<object>\" to the <SectionOutlet>.","If binding SectionName dynamically, guard it so it is never null when the outlet renders, or wrap the outlet in @if (!string.IsNullOrEmpty(name)).","Share a constant for section names so the outlet always matches the corresponding SectionContent."],"exampleFix":"// before\n<SectionOutlet />\n// after\n<SectionOutlet SectionName=\"alerts\" />","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(sectionName) && sectionId is null)\n    throw new InvalidOperationException(\"SectionOutlet requires SectionName or SectionId.\");","typeGuard":"static bool HasSectionIdentifier(string? name, object? id)\n    => !string.IsNullOrEmpty(name) || id is not null;","tryCatchPattern":null,"preventionTips":["Always set SectionName or SectionId on <SectionOutlet>.","Guard dynamic bindings so the identifier is never null at render time.","Pair each SectionOutlet with a matching SectionContent using a shared constant or object."],"tags":["blazor","sections","sectionoutlet","configuration","invalidoperationexception"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}