dotnet/aspnetcore · error · ArgumentNullException
layoutType
Error message
layoutType
What it means
LayoutAttribute's constructor requires a non-null layout type. A null layout type is meaningless and is rejected with ArgumentNullException.
Source
Thrown at src/Components/Components/src/LayoutAttribute.cs:21
using System.Diagnostics.CodeAnalysis;
using static Microsoft.AspNetCore.Internal.LinkerFlags;
namespace Microsoft.AspNetCore.Components;
/// <summary>
/// Indicates that the associated component type uses a specified layout.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class LayoutAttribute : Attribute
{
/// <summary>
/// Constructs an instance of <see cref="LayoutAttribute"/>.
/// </summary>
/// <param name="layoutType">The type of the layout.</param>
public LayoutAttribute([DynamicallyAccessedMembers(Component)] Type layoutType)
{
LayoutType = layoutType ?? throw new ArgumentNullException(nameof(layoutType));
if (!typeof(IComponent).IsAssignableFrom(layoutType))
{
throw new ArgumentException($"Invalid layout type: {layoutType.FullName} " +
$"does not implement {typeof(IComponent).FullName}.");
}
// Note that we can't validate its acceptance of a 'Body' parameter at this stage,
// because the contract doesn't force them to be known statically. However it will
// be a runtime error if the referenced component type rejects the 'Body' parameter
// when it gets used.
}
/// <summary>
/// The type of the layout. The type must implement <see cref="IComponent"/>
/// and must accept a parameter with the name 'Body'.
/// </summary>
[DynamicallyAccessedMembers(Component)]View on GitHub (pinned to 3600ca084e)
Solutions
- Pass a concrete layout type (a Razor component) to LayoutAttribute.
- Omit the Layout attribute entirely if no layout is needed.
- Resolve the layout type via a non-null default before applying the attribute.
Example fix
// before [Layout(null)] // after [Layout(typeof(MainLayout))]
Defensive patterns
Strategy: validation
Validate before calling
ArgumentNullException.ThrowIfNull(layoutType); var attr = new LayoutAttribute(layoutType);
Prevention
- Pass a concrete layout component type to LayoutAttribute.
- Omit the attribute when no layout is required.
- Validate dynamic layout selection returns non-null before applying.
When it happens
Trigger: [Layout(null)] on a component, or programmatically new LayoutAttribute(null).
Common situations: Dynamic layout type that resolves to null, refactoring that leaves a null reference, or misconfigured layout selection logic.
Related errors
- Invalid layout type: {layoutType.FullName} does not implemen
- componentActivator
- propertyActivator
- Valueless attributes may only be added immediately after fra
- The {nameof(frame.FrameType)} must be {RenderTreeFrameType.A
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/4c6f02a88d5c9481.
Report an issue: GitHub.