dotnet/aspnetcore · error · InvalidOperationException
Do not specify both 'Authorized' and 'ChildContent'.
Error message
Do not specify both 'Authorized' and 'ChildContent'.
What it means
Thrown by AuthorizeViewCore.OnParametersSetAsync when both the 'Authorized' and 'ChildContent' RenderFragment parameters are non-null on an AuthorizeView-derived component. These two parameters are semantically equivalent (both render when the user is authorized); 'ChildContent' exists for convenience and 'Authorized' for symmetry with 'NotAuthorized'. The framework treats specifying both as a configuration error because the intent is ambiguous.
Source
Thrown at src/Components/Authorization/src/AuthorizeViewCore.cs:80
{
var authorized = Authorized ?? ChildContent;
builder.AddContent(0, authorized?.Invoke(currentAuthenticationState!));
}
else
{
builder.AddContent(0, NotAuthorized?.Invoke(currentAuthenticationState!));
}
}
/// <inheritdoc />
protected override async Task OnParametersSetAsync()
{
// We allow 'ChildContent' for convenience in basic cases, and 'Authorized' for symmetry
// with 'NotAuthorized' in other cases. Besides naming, they are equivalent. To avoid
// confusion, explicitly prevent the case where both are supplied.
if (ChildContent != null && Authorized != null)
{
throw new InvalidOperationException($"Do not specify both '{nameof(Authorized)}' and '{nameof(ChildContent)}'.");
}
if (AuthenticationState == null)
{
throw new InvalidOperationException($"Authorization requires a cascading parameter of type Task<{nameof(AuthenticationState)}>. Consider using {typeof(CascadingAuthenticationState).Name} to supply this.");
}
// Clear the previous result of authorization
// This will cause the Authorizing state to be displayed until the authorization has been completed
isAuthorized = null;
currentAuthenticationState = await AuthenticationState;
isAuthorized = await IsAuthorizedAsync(currentAuthenticationState.User);
}
/// <summary>
/// Gets the data required to apply authorization rules.
/// </summary>View on GitHub (pinned to 294cab2f9b)
Solutions
- Remove one of the two: use either ChildContent OR Authorized, never both.
- If you need explicit NotAuthorized/Authorizing templates alongside authorized content, switch to using <Authorized> and drop the unnamed child content.
- If you only need simple authorized display, keep ChildContent and remove the <Authorized> element.
Example fix
// before
<AuthorizeView>
<Authorized>
<p>You are signed in.</p>
</Authorized>
<ChildContent>
<p>You are signed in.</p>
</ChildContent>
</AuthorizeView>
// after
<AuthorizeView>
<Authorized>
<p>You are signed in.</p>
</Authorized>
<NotAuthorized>
<p>Please sign in.</p>
</NotAuthorized>
</AuthorizeView> Defensive patterns
Strategy: validation
Validate before calling
// Before rendering, ensure not both are set
if (authorizeView.Authorized != null && authorizeView.ChildContent != null)
{
throw new InvalidOperationException("Specify only one of Authorized or ChildContent.");
} Prevention
- In markup, choose one approach per AuthorizeView: either unnamed child content or explicit <Authorized>.
- When adding <Authorized>/<NotAuthorized> templates, remove the unnamed child content block.
When it happens
Trigger: Setting both <ChildContent> and <Authorized> child content on the same <AuthorizeView> element in Razor markup, or assigning both ChildContent and Authorized properties programmatically. The check runs on every parameter set cycle (AuthorizeViewCore.cs:78-81).
Common situations: A developer adds an <Authorized> template to an existing <AuthorizeView> that already uses its default child content (ChildContent), forgetting to remove the original. Also happens when refactoring from simple to explicit authorized/not-authorized templates.
Related errors
- The authorization data specifies an authentication scheme wi
- EqualTo validator requires a non-empty "other" parameter.
- FileExtensions validator requires a non-empty "extensions" p
- Range validator requires at least one of "min" or "max" para
- regex validator requires a non-empty "pattern" parameter.
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/8572b8b3da9a3a31.
Report an issue: GitHub.