{"record":{"id":"b1d29f46fceb11eb","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-element","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'element')","messagePattern":"Value cannot be null\\. \\(Parameter 'element'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/Engine/Design/UICloner.cs","lineNumber":24,"sourceCode":"using System.IO;\nusing Stride.Core.Serialization;\nusing Stride.UI;\n\nnamespace Stride.Engine.Design\n{\n    public class UICloner\n    {\n        private static readonly EntityCloner.CloneContext CloneContext = new EntityCloner.CloneContext();\n        private static SerializerSelector cloneSerializerSelector;\n\n        // CloneObject TLS used to clone objects, so that we don't create one everytime we clone\n        [ThreadStatic] private static HashSet<object> clonedElementsLazy;\n\n        private static HashSet<object> ClonedElements => clonedElementsLazy ?? (clonedElementsLazy = new HashSet<object>());\n\n        public static UIElement Clone(UIElement element)\n        {\n            if (element == null) throw new ArgumentNullException(nameof(element));\n            var clonedObjects = ClonedElements;\n            try\n            {\n                clonedObjects.Add(element);\n                var clone = Clone(clonedObjects, element);\n                return clone;\n            }\n            finally\n            {\n                clonedObjects.Clear();\n            }\n        }\n\n        private static T Clone<T>(HashSet<object> clonedObjects, T entity) where T : class\n        {\n            if (cloneSerializerSelector == null)\n            {\n                cloneSerializerSelector = new SerializerSelector(true, false, \"Default\", \"Clone\");","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/Engine/Design/UICloner.cs#L6-L42","documentation":"Argument-null validation in UICloner.Clone: the element (UIElement) to clone is null. The cloner creates a copy of a library UI element for a UI component; with no source element there is nothing to clone, so it rejects the call with ArgumentNullException named 'element' ( surfaced as 'Value cannot be null. (Parameter element)').","triggerScenarios":"Calling UICloner.Clone(null) directly; instantiating a UI library element whose lookup returned null and then cloning it; a UILibrary.UIElements dictionary entry that is null.","commonSituations":"Instantiating prefabs from a library where the named element is missing or the library failed to load; editor scripts cloning a selection that resolved to null; deserialization leaving a UIElement reference null.","solutions":["Null-check the source element before cloning","When using library instantiation, verify the element name exists in library.UIElements before cloning","Fix the asset/library so the referenced UI element actually exists"],"exampleFix":"// before\nvar copy = UICloner.Clone(rootElement.Child); // Child is null -> throws\n// after\nif (rootElement.Child != null)\n    copy = UICloner.Clone(rootElement.Child);","handlingStrategy":"validation","validationCode":"if (element == null)\n    return null; // or log which element failed to resolve","typeGuard":"bool CanClone(UIElement e) => e != null;","tryCatchPattern":"try\n{\n    var copy = UICloner.Clone(element);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"element\")\n{\n    // the source element was never loaded/found; fix asset or lookup\n}","preventionTips":["Verify library.UIElements.ContainsKey(name) before cloning","Ensure library assets are loaded before instantiation","Null-check deserialized UIElement references"],"tags":["ui","clone","null-argument"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}