{"record":{"id":"73c7f13184b20ef7","repo":"dotnet/aspnetcore","slug":"no-preceding-attribute-frame-exists","errorCode":null,"errorMessage":"No preceding attribute frame exists.","messagePattern":"No preceding attribute frame exists\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Rendering/RenderTreeBuilder.cs","lineNumber":477,"sourceCode":"    }\n\n    /// <summary>\n    /// <para>\n    /// Indicates that the preceding attribute represents an event handler\n    /// whose execution updates the attribute with name <paramref name=\"updatesAttributeName\"/>.\n    /// </para>\n    /// <para>\n    /// This information is used by the rendering system to determine whether\n    /// to accept a value update for the other attribute when receiving a\n    /// call to the event handler.\n    /// </para>\n    /// </summary>\n    /// <param name=\"updatesAttributeName\">The name of another attribute whose value can be updated when the event handler is executed.</param>\n    public void SetUpdatesAttributeName(string updatesAttributeName)\n    {\n        if (_entries.Count == 0)\n        {\n            throw new InvalidOperationException(\"No preceding attribute frame exists.\");\n        }\n\n        ref var prevFrame = ref _entries.Buffer[_entries.Count - 1];\n        if (prevFrame.FrameTypeField != RenderTreeFrameType.Attribute)\n        {\n            throw new InvalidOperationException($\"Incorrect frame type: '{prevFrame.FrameTypeField}'\");\n        }\n\n        prevFrame.AttributeEventUpdatesAttributeNameField = updatesAttributeName;\n    }\n\n    /// <summary>\n    /// Appends a frame representing a child component.\n    /// </summary>\n    /// <typeparam name=\"TComponent\">The type of the child component.</typeparam>\n    /// <param name=\"sequence\">An integer that represents the position of the instruction in the source code.</param>\n    public void OpenComponent<[DynamicallyAccessedMembers(Component)] TComponent>(int sequence) where TComponent : notnull, IComponent\n        => OpenComponentUnchecked(sequence, typeof(TComponent));","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/Rendering/RenderTreeBuilder.cs#L459-L495","documentation":"SetUpdatesAttributeName was called when the builder has no frames yet (_entries.Count == 0). The method tags the most recently appended frame as one whose value should be refreshed when an event handler fires, so it requires a preceding Attribute frame to operate on.","triggerScenarios":"Calling builder.SetUpdatesAttributeName(name) as the very first operation, or after Clear() with nothing re-appended. Misordered manual tree construction.","commonSituations":"Hand-written RenderTreeBuilder code that emits event-handler wiring. Custom Razor-emitted code generators that emit SetUpdatesAttributeName at the wrong point.","solutions":["Call AddAttribute(...) for the event-handler attribute before SetUpdatesAttributeName.","Verify the builder has at least one frame and the previous frame is an Attribute before invoking.","Restructure emission order so the update-target attribute precedes the SetUpdatesAttributeName call."],"exampleFix":"// before\nbuilder.SetUpdatesAttributeName(\"value\");\nbuilder.OpenElement(0, \"input\");\n\n// after\nbuilder.OpenElement(0, \"input\");\nbuilder.AddAttribute(1, \"oninput\", handler);\nbuilder.SetUpdatesAttributeName(\"value\");","handlingStrategy":"validation","validationCode":"// Guard in custom tree-build code\nif (entries.Count == 0) throw new InvalidOperationException(\"Append an attribute first.\");\nbuilder.SetUpdatesAttributeName(name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure an Attribute frame is appended before SetUpdatesAttributeName.","Track entry count in custom builders and skip if empty."],"tags":["blazor","render-tree-builder","event-handler","ordering","api-misuse"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}