{"record":{"id":"58401c1083d65c43","repo":"stride3d/stride","slug":"the-control-corresponding-to-the-given-parentid-is-a","errorCode":null,"errorMessage":"The control corresponding to the given parentId is a ContentControl that already has a Content.","messagePattern":"The control corresponding to the given parentId is a ContentControl that already has a Content\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Services/UIEditorController.cs","lineNumber":237,"sourceCode":"                    RootElements[assetSidePart.Id] = gameSidePart;\n                }\n                else\n                {\n                    var parentElement = (UIElement)FindPart(parentId.Value);\n                    if (parentElement == null)\n                        throw new InvalidOperationException($\"The given {nameof(parentId)} does not correspond to any existing part.\");\n\n                    var panel = parentElement as Panel;\n                    var contentControl = parentElement as ContentControl;\n                    if (panel != null)\n                    {\n                        GameSideNodeContainer.GetNode(panel.Children).Add(gameSidePart);\n                    }\n                    else if (contentControl != null)\n                    {\n                        if (contentControl.Content != null)\n                        {\n                            throw new InvalidOperationException($\"The control corresponding to the given {nameof(parentId)} is a ContentControl that already has a Content.\");\n                        }\n                        GameSideNodeContainer.GetNode(contentControl)[nameof(contentControl.Content)].Update(gameSidePart);\n                    }\n                }\n            });\n        }\n\n        /// <inheritdoc />\n        public override Task RemovePart([NotNull] UIHierarchyItemViewModel parent, UIElement assetSidePart)\n        {\n            EnsureAssetAccess();\n\n            return InvokeAsync(() =>\n            {\n                Logger.Debug($\"Removing element {assetSidePart.Id} from game-side scene\");\n                var partId = new AbsoluteId(AssetId.Empty, assetSidePart.Id);\n                var part = (UIElement)FindPart(partId);\n                if (part == null)","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Services/UIEditorController.cs#L219-L255","documentation":"UIEditorController.AddPart throws this InvalidOperationException when the target parent is a ContentControl that already has Content. A ContentControl holds exactly one child; assigning a second would silently overwrite existing game-side content, so the controller refuses the add.","triggerScenarios":"Adding a part whose parentId refers to a ContentControl that already contains a child; calling AddPart twice with the same single-child parent; dragging multiple elements into a single-slot container.","commonSituations":"Duplicating elements into a button/content host that already has content, replaying scripts against an already-populated layout, drag-drop of several items onto one ContentControl.","solutions":["Remove or move the existing content of the ContentControl before adding the new part.","Use a Panel-based parent (StackPanel, Grid) that accepts multiple children.","Check the parent's content (ContentControl.Content != null) before calling AddPart.","If replacement is intended, update the existing content node instead of adding a new part."],"exampleFix":"// before\ncontroller.AddPart(newPart, contentControlId); // throws if content exists\n// after\nvar parent = FindViewModel(contentControlId) as ContentControlViewModel;\nif (parent?.Content == null)\n    controller.AddPart(newPart, contentControlId);\nelse\n    controller.AddPart(newPart, panelParentId);\n","handlingStrategy":"type-guard","validationCode":"var parentVm = FindViewModel(parentId) as ContentControlViewModel;\nbool canAdd = parentVm != null && parentVm.Content == null;","typeGuard":"bool CanHostContent(UIElementViewModel parent) => parent is ContentControlViewModel cc && cc.Content == null;","tryCatchPattern":"try { controller.AddPart(newPart, parentId); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"already has a Content\")) {\n    // pick a panel parent or clear the existing content first\n}","preventionTips":["Check ContentControl content occupancy before adding children.","Prefer Panel parents for multiple children.","Avoid duplicate add calls against single-slot containers.","Centralize parent selection logic to respect container capacity."],"tags":["csharp","stride","ui-editor","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}