{"record":{"id":"092696224891b141","repo":"stride3d/stride","slug":"the-given-id-cannot-be-found-in-the-root-parts-of-this","errorCode":null,"errorMessage":"The given id cannot be found in the root parts of this library.","messagePattern":"The given id cannot be found in the root parts of this library\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/UI/UILibraryAsset.cs","lineNumber":69,"sourceCode":"        /// <summary>\n        /// Creates a instance of the given control that can be added to another <see cref=\"UIAssetBase\"/>.\n        /// </summary>\n        /// <param name=\"targetContainer\">The container in which the instance will be added.</param>\n        /// <param name=\"targetLocation\">The location of this asset.</param>\n        /// <param name=\"elementId\">The id of the element to instantiate.</param>\n        /// <param name=\"instanceId\">The identifier of the created instance.</param>\n        /// <returns>An <see cref=\"AssetCompositeHierarchyData{UIElementDesign, UIElement}\"/> containing the cloned elements of </returns>\n        /// <remarks>This method will update the <see cref=\"Asset.BaseParts\"/> property of the <see paramref=\"targetContainer\"/>.</remarks>\n        [NotNull]\n        public AssetCompositeHierarchyData<UIElementDesign, UIElement> CreateElementInstance(UIAssetBase targetContainer, [NotNull] string targetLocation, Guid elementId, out Guid instanceId)\n        {\n            // TODO: make a common base method in AssetCompositeHierarchy - the beginning of the method is similar to CreatePrefabInstance\n            var idRemapping = new Dictionary<Guid, Guid>();\n            var instance = (UILibraryAsset)CreateDerivedAsset(targetLocation, out idRemapping);\n\n            var rootElementId = idRemapping[elementId];\n            if (instance.Hierarchy.RootParts.All(x => x.Id != rootElementId))\n                throw new ArgumentException(@\"The given id cannot be found in the root parts of this library.\", nameof(elementId));\n\n            instanceId = instance.Hierarchy.Parts.Values.FirstOrDefault()?.Base?.InstanceId ?? Guid.NewGuid();\n\n            var result = new AssetCompositeHierarchyData<UIElementDesign, UIElement>();\n            result.RootParts.Add(instance.Hierarchy.Parts[rootElementId].UIElement);\n            result.Parts.Add(instance.Hierarchy.Parts[rootElementId]);\n            foreach (var element in this.EnumerateChildPartDesigns(instance.Hierarchy.Parts[rootElementId], instance.Hierarchy, true))\n            {\n                result.Parts.Add(element);\n            }\n            return result;\n        }\n    }\n}\n","sourceCodeStart":51,"sourceCodeEnd":84,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/UI/UILibraryAsset.cs#L51-L84","documentation":"UILibraryAsset.CreateElementInstance creates a derived asset instance and remaps element ids; it then requires the requested elementId (after remapping) to be among the instance hierarchy's root parts. If it is a nested element rather than a root part, it throws ArgumentException naming elementId. Only top-level UI elements of the library can be instantiated by this API.","triggerScenarios":"Calling CreateElementInstance with the Guid of a UIElement that exists in the library but is not a direct root part of the hierarchy (e.g. a child inside a grid/panel element).","commonSituations":"Picking a nested UIElement id from the designer and passing it to this method; element was moved under another parent after code referenced its id; refactoring removed the element from root level.","solutions":["Pass the Guid of a root-level UIElement of the UI library asset, not a nested child.","Look up the desired id in the asset's Hierarchy.RootParts to verify before calling.","If you need a nested element, restructure the library so that element is a root part."],"exampleFix":"// before\nlibrary.CreateElementInstance(childElementId, out var instanceId); // nested id\n// after\nvar root = library.Hierarchy.RootParts.First(x => x.Name == \"MyButton\");\nlibrary.CreateElementInstance(root.Id, out var instanceId);","handlingStrategy":"validation","validationCode":"bool isRoot = library.Hierarchy.RootParts.Any(x => x.Id == elementId);\nif (!isRoot)\n    throw new ArgumentException($\"Element {elementId} is not a root part of the UI library\");","typeGuard":"bool IsRootElement(UILibraryAsset lib, Guid id) =>\n    lib.Hierarchy.RootParts.Any(x => x.Id == id);","tryCatchPattern":"try\n{\n    library.CreateElementInstance(elementId, out var instanceId);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"elementId\")\n{\n    logger.Error($\"Pick a root-level UIElement id: {ex.Message}\");\n}","preventionTips":["Resolve element ids from Hierarchy.RootParts at runtime instead of hardcoding","Re-check ids after moving elements in the UI designer","Restructure the library so instantiable elements sit at the root level"],"tags":["ui","assets","guid","argument-validation"],"backgroundTag":"invalid-argument-value","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"}