{"record":{"id":"4c6f02a88d5c9481","repo":"dotnet/aspnetcore","slug":"layouttype","errorCode":null,"errorMessage":"layoutType","messagePattern":"layoutType","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/LayoutAttribute.cs","lineNumber":21,"sourceCode":"\nusing System.Diagnostics.CodeAnalysis;\nusing static Microsoft.AspNetCore.Internal.LinkerFlags;\n\nnamespace Microsoft.AspNetCore.Components;\n\n/// <summary>\n/// Indicates that the associated component type uses a specified layout.\n/// </summary>\n[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]\npublic sealed class LayoutAttribute : Attribute\n{\n    /// <summary>\n    /// Constructs an instance of <see cref=\"LayoutAttribute\"/>.\n    /// </summary>\n    /// <param name=\"layoutType\">The type of the layout.</param>\n    public LayoutAttribute([DynamicallyAccessedMembers(Component)] Type layoutType)\n    {\n        LayoutType = layoutType ?? throw new ArgumentNullException(nameof(layoutType));\n\n        if (!typeof(IComponent).IsAssignableFrom(layoutType))\n        {\n            throw new ArgumentException($\"Invalid layout type: {layoutType.FullName} \" +\n                $\"does not implement {typeof(IComponent).FullName}.\");\n        }\n\n        // Note that we can't validate its acceptance of a 'Body' parameter at this stage,\n        // because the contract doesn't force them to be known statically. However it will\n        // be a runtime error if the referenced component type rejects the 'Body' parameter\n        // when it gets used.\n    }\n\n    /// <summary>\n    /// The type of the layout. The type must implement <see cref=\"IComponent\"/>\n    /// and must accept a parameter with the name 'Body'.\n    /// </summary>\n    [DynamicallyAccessedMembers(Component)]","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/LayoutAttribute.cs#L3-L39","documentation":"LayoutAttribute's constructor requires a non-null layout type. A null layout type is meaningless and is rejected with ArgumentNullException.","triggerScenarios":"[Layout(null)] on a component, or programmatically new LayoutAttribute(null).","commonSituations":"Dynamic layout type that resolves to null, refactoring that leaves a null reference, or misconfigured layout selection logic.","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."],"exampleFix":"// before\n[Layout(null)]\n// after\n[Layout(typeof(MainLayout))]","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(layoutType);\nvar attr = new LayoutAttribute(layoutType);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["blazor","layout","argument-null","attribute"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}