{"record":{"id":"e1e434527972f38f","repo":"dotnet/aspnetcore","slug":"nameof-sectioncontent-requires-a-non-null-value","errorCode":null,"errorMessage":"{nameof(SectionContent)} 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/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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/Sections/SectionContent.cs#L50-L86","documentation":"SectionContent must be associated with at least one identifier — either a SectionName string or a SectionId object — so the registry knows which SectionOutlet to feed. If both are null, the component has no key under which to register itself and throws InvalidOperationException. This is the symmetric counterpart to the both-set check.","triggerScenarios":"Declaring <SectionContent>...</SectionContent> with neither SectionName nor SectionId set. The component has no other default identifier.","commonSituations":"Adding a SectionContent and forgetting to specify the target; refactoring markup and dropping the identifier attribute; binding SectionName to an expression that evaluates to null at runtime.","solutions":["Add either SectionName=\"<name>\" or SectionId=\"@<object>\" to the <SectionContent> element.","If binding SectionName to an expression, ensure it is never null at render time (provide a default or guard the render with @if).","Use a constant for shared section names to avoid typos that produce null bindings."],"exampleFix":"// before\n<SectionContent>\n    <p>Will never show</p>\n</SectionContent>\n// after\n<SectionContent SectionName=\"alerts\">\n    <p>Visible where <SectionOutlet SectionName=\"alerts\" /> lives</p>\n</SectionContent>","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(sectionName) && sectionId is null)\n    throw new InvalidOperationException(\"SectionContent 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 <SectionContent>.","Guard dynamic bindings: @if (!string.IsNullOrEmpty(name)) { <SectionContent SectionName=@name>...</SectionContent> }.","Keep SectionContent identifiers paired with matching SectionOutlet identifiers."],"tags":["blazor","sections","sectioncontent","configuration","invalidoperationexception"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}