{"record":{"id":"3106220da673e9c5","repo":"stride3d/stride","slug":"value-cannot-be-null-parameter-library","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'library')","messagePattern":"Value cannot be null\\. \\(Parameter 'library'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.UI/Engine/UILibraryExtensions.cs","lineNumber":22,"sourceCode":"using System;\nusing Stride.Engine.Design;\nusing Stride.UI;\n\nnamespace Stride.Engine\n{\n    public static class UILibraryExtensions\n    {\n        /// <summary>\n        /// Instantiates a copy of the element of the library identified by <paramref name=\"name\"/>.\n        /// </summary>\n        /// <typeparam name=\"TElement\">The type of the element.</typeparam>\n        /// <param name=\"library\">The library.</param>\n        /// <param name=\"name\">The name of the element in the library.</param>\n        /// <returns></returns>\n        public static TElement InstantiateElement<TElement>(this UILibrary library, string name)\n            where TElement : UIElement\n        {\n            if (library == null) throw new ArgumentNullException(nameof(library));\n\n            UIElement source;\n            if (library.UIElements.TryGetValue(name, out source))\n            {\n                return UICloner.Clone(source) as TElement;\n            }\n            return null;\n        }\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":33,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.UI/Engine/UILibraryExtensions.cs#L4-L33","documentation":"Argument-null validation in UILibraryExtensions.InstantiateElement<TElement>: the library (UILibrary) extension-method receiver is null. Instantiating an element requires looking up the element by name inside the library; a null library has no elements to search, so the call fails with ArgumentNullException named 'library'.","triggerScenarios":"Calling myLibrary.InstantiateElement<Button>(\"name\") where the library field/property is null (asset not loaded, service not injected, reference not wired in the editor).","commonSituations":"Forgetting to assign a UILibrary asset reference in a Stride scene/component; loading order issues where the UI is instantiated before the library asset finished loading; script properties left at their defaults.","solutions":["Assign the UILibrary asset reference on the component/script before instantiating","Wait for/load the library asset (Content.Load) before calling InstantiateElement","Null-check the library (or the resolved property) before invoking the extension"],"exampleFix":"// before\npublic UILibrary Library; // left null in editor\nvar btn = Library.InstantiateElement<Button>(\"OkButton\"); // throws\n// after\nvar btn = Library?.InstantiateElement<Button>(\"OkButton\");\n// or check in code: if (Library == null) LoadLibrary();","handlingStrategy":"validation","validationCode":"if (library == null || !library.UIElements.ContainsKey(name))\n    return null; // element cannot be instantiated","typeGuard":"bool CanInstantiate(UILibrary lib) => lib?.UIElements != null;","tryCatchPattern":"try\n{\n    var btn = library.InstantiateElement<Button>(\"OkButton\");\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"library\")\n{\n    // library reference not assigned; load or wire the asset first\n}","preventionTips":["Assign UILibrary references in the editor or load via Content.Load before use","Check load order: instantiate UI only after assets resolve","Prefer ?./null-checks when a library reference is optional"],"tags":["ui","library","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-23T08:17:48.524Z"}