{"record":{"id":"084dc28ae2f8e363","repo":"dotnet/aspnetcore","slug":"the-enclosing-frame-is-not-of-the-required-type-c","errorCode":null,"errorMessage":"The enclosing frame is not of the required type 'Component'.","messagePattern":"The enclosing frame is not of the required type 'Component'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Rendering/RenderTreeBuilder.cs","lineNumber":658,"sourceCode":"\n        // Note that a ComponentRenderMode frame is technically a child of the Component frame to which it applies,\n        // hence the terminology of \"adding\" it rather than \"setting\" it. For performance reasons, the diffing system\n        // will only look for ComponentRenderMode frames:\n        // [a] when the HasCallerSpecifiedRenderMode flag is set on the Component frame\n        // [b] up until the first child that is *not* a ComponentRenderMode frame or any other header frame type\n        //     that we may define in the future\n\n        var parentFrameIndex = GetCurrentParentFrameIndex();\n        if (!parentFrameIndex.HasValue)\n        {\n            throw new InvalidOperationException(\"There is no enclosing component frame.\");\n        }\n\n        var parentFrameIndexValue = parentFrameIndex.Value;\n        ref var parentFrame = ref _entries.Buffer[parentFrameIndexValue];\n        if (parentFrame.FrameTypeField != RenderTreeFrameType.Component)\n        {\n            throw new InvalidOperationException($\"The enclosing frame is not of the required type '{nameof(RenderTreeFrameType.Component)}'.\");\n        }\n\n        parentFrame.ComponentFrameFlagsField |= ComponentFrameFlags.HasCallerSpecifiedRenderMode;\n\n        _entries.AppendComponentRenderMode(renderMode);\n        _lastNonAttributeFrameType = RenderTreeFrameType.ComponentRenderMode;\n    }\n\n    /// <summary>\n    /// Assigns a name to an event in the enclosing element.\n    /// </summary>\n    /// <param name=\"eventType\">The event type, e.g., 'onsubmit'.</param>\n    /// <param name=\"assignedName\">The application-assigned name.</param>\n    public void AddNamedEvent(string eventType, string assignedName)\n    {\n        ArgumentNullException.ThrowIfNull(eventType);\n        ArgumentException.ThrowIfNullOrEmpty(assignedName);\n","sourceCodeStart":640,"sourceCodeEnd":676,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/Rendering/RenderTreeBuilder.cs#L640-L676","documentation":"Second guard in AddComponentRenderMode: an enclosing frame exists but its type is not Component (it is Element or Region). Render mode applies only to a component frame, so attaching it to an element or region scope is invalid.","triggerScenarios":"Calling AddComponentRenderMode(mode) while the current parent is an element opened via OpenElement, or inside a region. In .razor this surfaces as a @rendermode placed on an HTML element instead of a component.","commonSituations":"Typing @rendermode=\"InteractiveServer\" on a <div> rather than on the component; manual RenderFragment that opens an element then sets render mode; copy-paste of a component block where the open-element line wasn't swapped for open-component.","solutions":["Ensure the frame immediately enclosing the render-mode call is a Component (OpenComponent), not an Element or Region.","Move @rendermode to the child component tag, or call AddComponentRenderMode right after OpenComponent.","Check the OpenElement/OpenComponent ordering around the call."],"exampleFix":"// before\nbuilder.OpenElement(0, \"div\");\nbuilder.AddComponentRenderMode(RenderMode.InteractiveServer);\nbuilder.CloseElement();\n\n// after\nbuilder.OpenComponent<MyComp>(0);\nbuilder.AddComponentRenderMode(RenderMode.InteractiveServer);\nbuilder.CloseComponent();","handlingStrategy":"validation","validationCode":"// Track whether the current parent is a Component (not Element/Region) before setting render mode.\nbool _inComponent = false;\nvoid Render(RenderTreeBuilder b) {\n    b.OpenComponent<MyComp>(0); _inComponent = true;\n    if (_inComponent) b.AddComponentRenderMode(MyRenderMode);\n    _inComponent = false; b.CloseComponent();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply @rendermode to the child component tag, never to an enclosing <div>.","In manual code, confirm the last Open* was OpenComponent before AddComponentRenderMode.","Remember render mode attaches to a Component frame; an Element frame rejects it."],"tags":["blazor","rendering","rendertree","rendermode","interactive"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}