{"record":{"id":"dd6263241186f88e","repo":"stride3d/stride","slug":"the-given-parentid-does-not-correspond-to-any-existing-part","errorCode":null,"errorMessage":"The given parentId does not correspond to any existing part.","messagePattern":"The given parentId does not correspond to any existing part\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Services/UIEditorController.cs","lineNumber":225,"sourceCode":"        public override Task AddPart([NotNull] UIHierarchyItemViewModel parent, UIElement assetSidePart)\n        {\n            EnsureAssetAccess();\n\n            var gameSidePart = ClonePartForGameSide(parent.Asset.Asset, assetSidePart);\n            return InvokeAsync(() =>\n            {\n                Logger.Debug($\"Adding element {assetSidePart.Id} to game-side scene\");\n\n                var parentId = (parent as UIElementViewModel)?.Id;\n                if (parentId == null)\n                {\n                    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        }","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/Services/UIEditorController.cs#L207-L243","documentation":"UIEditorController.AddPart throws this InvalidOperationException when the parentId for a new UI part cannot be resolved to an existing game-side UIElement via FindPart. The controller maintains a game-side mirror of the asset hierarchy; attaching a child to an unknown parent would corrupt that mirror, so it fails fast.","triggerScenarios":"Calling AddPart with a parentId that was never registered, was already removed by a prior RemovePart, belongs to a different asset (AbsoluteId asset-id mismatch), or whose game-side element was not yet created.","commonSituations":"Editor plugins/scripts reusing stale ids after undo/redo, out-of-order updates where the child is added before its parent, id collisions across assets.","solutions":["Verify the parentId exists in the current UI hierarchy before calling AddPart.","Create/register the parent part first so parent-before-child ordering holds.","Re-fetch ids after undo/redo or asset reload; never cache ids across transactions.","Confirm the AbsoluteId's asset id matches the currently loaded UI asset."],"exampleFix":"// before\ncontroller.AddPart(newPart, staleParentId);\n// after\nvar parent = viewModel.TreeRoot.Flatten().FirstOrDefault(e => e.Id == staleParentId);\nif (parent != null)\n    controller.AddPart(newPart, staleParentId);\n","handlingStrategy":"validation","validationCode":"bool parentExists = viewModel.TreeRoot.Flatten().Any(e => e.Id == parentId);\nif (!parentExists) throw new InvalidOperationException($\"Parent {parentId} not in hierarchy\");","typeGuard":"UIElementViewModel ResolveParent(AbsoluteId id) => viewModel.TreeRoot.Flatten().FirstOrDefault(e => e.Id == id);","tryCatchPattern":"try { controller.AddPart(newPart, parentId); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not correspond to any existing part\")) {\n    // recreate parent or skip\n}","preventionTips":["Validate parent ids against the live hierarchy before add operations.","Enforce parent-before-child ordering when building parts.","Never cache element ids across undo/redo or asset reloads.","Check that the AbsoluteId's asset id matches the loaded asset."],"tags":["csharp","stride","ui-editor","entity-not-found"],"backgroundTag":"entity-not-found","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"}