{"record":{"id":"1a21539848cdf8e4","repo":"stride3d/stride","slug":"argumentnullexception-session","errorCode":null,"errorMessage":"ArgumentNullException: session","messagePattern":"ArgumentNullException: session","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/ViewModels/NewProjectTemplateCollectionViewModel.cs","lineNumber":23,"sourceCode":"using System.Linq;\nusing Stride.Core.Assets.Editor.Settings;\nusing Stride.Core.Assets.Editor.ViewModel;\nusing Stride.Core.Assets.Templates;\nusing Stride.Core.Extensions;\nusing Stride.Core.IO;\nusing Stride.Core.Presentation.ViewModels;\n\nnamespace Stride.Core.Assets.Editor.Components.TemplateDescriptions.ViewModels\n{\n    public class NewProjectTemplateCollectionViewModel : ProjectTemplateCollectionViewModel\n    {\n        private readonly TemplateDescriptionGroupViewModel rootGroup;\n        private bool arePropertiesValid;\n\n        public NewProjectTemplateCollectionViewModel(IViewModelServiceProvider serviceProvider, SessionViewModel session)\n            : base(serviceProvider)\n        {\n            if (session == null) throw new ArgumentNullException(nameof(session));\n            Session = session;\n\n            rootGroup = new TemplateDescriptionGroupViewModel(serviceProvider, \"All templates\");\n\n            // Add a default General group\n            var defaultGroup = new TemplateDescriptionGroupViewModel(rootGroup, \"General\");\n            \n            foreach (TemplateDescription template in session.FindTemplates(TemplateScope.Session))\n            {\n                if (!IsAssetsOnlyTemplate(template))\n                    continue;\n\n                var viewModel = new PackageTemplateViewModel(serviceProvider, template, session);\n                var group = ProcessGroup(rootGroup, template.Group) ?? defaultGroup;\n                group.Templates.Add(viewModel);\n            }\n\n            Location = session.SolutionPath.GetFullDirectory() ?? InternalSettings.TemplatesWindowDialogLastNewSessionTemplateDirectory.GetValue();","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/ViewModels/NewProjectTemplateCollectionViewModel.cs#L5-L41","documentation":"The NewProjectTemplateCollectionViewModel constructor requires a SessionViewModel representing the editor session; it throws ArgumentNullException when session is null because the template collection is built from the session's template descriptions.","triggerScenarios":"Constructing NewProjectTemplateCollectionViewModel with a null session — e.g. the SessionViewModel has not been created yet, or a service locator returned null before session initialization.","commonSituations":"Opening the new-project dialog before the editor session loads; DI ordering issues where the view model is built before the session; failed session load silently yielding null.","solutions":["Ensure the SessionViewModel is fully initialized before constructing this view model","Null-check/guard the session source (service locator or parent view model)","Fix initialization order so the session is created before template-dependent UI"],"exampleFix":"// before\nvar vm = new NewProjectTemplateCollectionViewModel(serviceProvider, session); // session may be null\n// after\nif (session == null) throw new InvalidOperationException(\"Session must be initialized before showing project templates\");\nvar vm = new NewProjectTemplateCollectionViewModel(serviceProvider, session);","handlingStrategy":"validation","validationCode":"if (session == null) throw new InvalidOperationException(\"Editor session must be loaded before listing project templates\");","typeGuard":"bool SessionReady(SessionViewModel s) => s != null && s.IsInitialized;","tryCatchPattern":"try { var vm = new NewProjectTemplateCollectionViewModel(sp, session); } catch (ArgumentNullException ex) when (ex.ParamName == \"session\") { /* abort dialog open; report session not ready */ }","preventionTips":["Open template-dependent UI only after the session is initialized","Check session readiness via a flag/service before constructing the view model","Verify DI registration order guarantees the session exists first"],"tags":["null-argument","viewmodel","constructor"],"backgroundTag":"null-argument","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"}