{"record":{"id":"c54329f982229c4b","repo":"stride3d/stride","slug":"the-corresponding-ui-element-could-not-be-found-in-the","errorCode":null,"errorMessage":"The corresponding UI Element could not be found in the library","messagePattern":"The corresponding UI Element could not be found in the library","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/UIElementFromLibrary.cs","lineNumber":38,"sourceCode":"            : base(serviceProvider)\n        {\n            this.library = library;\n            Id = id;\n\n            var node = library.Session.AssetNodeContainer.GetNode(library.Asset)[nameof(UILibraryAsset.PublicUIElements)];\n            nameBinding = new MemberGraphNodeBinding<Dictionary<Guid, string>>(node, nameof(Name), OnPropertyChanging, OnPropertyChanged, library.UndoRedoService);\n        }\n\n        public Guid Id { get; }\n\n        public string Name => nameBinding.Value.ContainsKey(Id) ? nameBinding.Value[Id] : \"(undefined)\";\n\n        public string Category => library.Url;\n\n        public AssetCompositeHierarchyData<UIElementDesign, UIElement> Create(UIAssetBase targetAsset)\n        {\n            if (!library.Asset.Hierarchy.Parts.ContainsKey(Id))\n                throw new InvalidOperationException(\"The corresponding UI Element could not be found in the library\");\n\n            var asset = (UILibraryAsset)library.Asset;\n            return asset.CreateElementInstance(targetAsset, library.Url, Id);\n\n        }\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":46,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/UIEditor/ViewModels/UIElementFromLibrary.cs#L20-L46","documentation":"Thrown by UIElementFromLibrary.Create when the Id of the library-sourced UI element no longer exists in the referenced UI library asset's Hierarchy.Parts. Create is supposed to instantiate a copy of an element stored in a UI library; if the part keyed by Id is absent there is nothing to instantiate.","triggerScenarios":"Creating an element instance from a UIElementFromLibrary whose Id was removed or regenerated in the source UILibraryAsset (e.g. library edited/re-saved after the reference was captured, or the Id belongs to a different library asset).","commonSituations":"Stale references after the library asset was edited and a UI element deleted; merging library assets so IDs changed; copy-pasting elements that reference an old library version.","solutions":["Re-create the reference so it points at an Id that currently exists in the library asset.","Open the UI library asset and re-add/restore the missing element, or pick a different library element in the editor.","Verify library.Asset.Hierarchy.Parts.ContainsKey(Id) before calling Create and fall back to user selection if false."],"exampleFix":"// before\nvar element = uiElementFromLibrary.Create(targetAsset);\n// after\nif (!uiElementFromLibrary.library.Asset.Hierarchy.Parts.ContainsKey(uiElementFromLibrary.Id))\n    throw new InvalidOperationException($\"Library element {uiElementFromLibrary.Id} missing from {uiElementFromLibrary.library.Url}\");\nvar element = uiElementFromLibrary.Create(targetAsset);","handlingStrategy":"validation","validationCode":"bool exists = uiElementFromLibrary.library?.Asset?.Hierarchy?.Parts.ContainsKey(uiElementFromLibrary.Id) == true;","typeGuard":"static bool LibraryElementExists(UIElementFromLibrary e) => e?.library?.Asset?.Hierarchy?.Parts.ContainsKey(e.Id) ?? false;","tryCatchPattern":"try { var el = fromLibrary.Create(targetAsset); } catch (InvalidOperationException ex) { /* re-pick library element */ }","preventionTips":["Re-validate library references after editing the library asset.","Avoid persisting raw element ids across library versions; re-resolve by name/category.","Wrap Create calls with existence checks when automating editor tasks."],"tags":["stride","ui-library","stale-reference","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"}