stride3d/stride · error · ArgumentNullException
ArgumentNullException: session
Error message
ArgumentNullException: session
What it means
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.
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
Example fix
// before
var vm = new NewProjectTemplateCollectionViewModel(serviceProvider, session); // session may be null
// after
if (session == null) throw new InvalidOperationException("Session must be initialized before showing project templates");
var vm = new NewProjectTemplateCollectionViewModel(serviceProvider, session); Defensive patterns
Strategy: validation
Validate before calling
if (session == null) throw new InvalidOperationException("Editor session must be loaded before listing project templates"); Type guard
bool SessionReady(SessionViewModel s) => s != null && s.IsInitialized;
Try / catch
try { var vm = new NewProjectTemplateCollectionViewModel(sp, session); } catch (ArgumentNullException ex) when (ex.ParamName == "session") { /* abort dialog open; report session not ready */ } Prevention
- 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
When it happens
Trigger: Constructing NewProjectTemplateCollectionViewModel with a null session — e.g. the SessionViewModel has not been created yet, or a service locator returned null before session initialization.
Common situations: 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.
Related errors
- ArgumentNullException: templates
- ArgumentNullException: removeAction
- Value cannot be null. (Parameter 'values')
- entity must contain a non-null asset entity.
- ArgumentNullException: dependencyManager
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/1a21539848cdf8e4.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/ViewModels/NewProjectTemplateCollectionViewModel.cs:23
using System.Linq;
using Stride.Core.Assets.Editor.Settings;
using Stride.Core.Assets.Editor.ViewModel;
using Stride.Core.Assets.Templates;
using Stride.Core.Extensions;
using Stride.Core.IO;
using Stride.Core.Presentation.ViewModels;
namespace Stride.Core.Assets.Editor.Components.TemplateDescriptions.ViewModels
{
public class NewProjectTemplateCollectionViewModel : ProjectTemplateCollectionViewModel
{
private readonly TemplateDescriptionGroupViewModel rootGroup;
private bool arePropertiesValid;
public NewProjectTemplateCollectionViewModel(IViewModelServiceProvider serviceProvider, SessionViewModel session)
: base(serviceProvider)
{
if (session == null) throw new ArgumentNullException(nameof(session));
Session = session;
rootGroup = new TemplateDescriptionGroupViewModel(serviceProvider, "All templates");
// Add a default General group
var defaultGroup = new TemplateDescriptionGroupViewModel(rootGroup, "General");
foreach (TemplateDescription template in session.FindTemplates(TemplateScope.Session))
{
if (!IsAssetsOnlyTemplate(template))
continue;
var viewModel = new PackageTemplateViewModel(serviceProvider, template, session);
var group = ProcessGroup(rootGroup, template.Group) ?? defaultGroup;
group.Templates.Add(viewModel);
}
Location = session.SolutionPath.GetFullDirectory() ?? InternalSettings.TemplatesWindowDialogLastNewSessionTemplateDirectory.GetValue();View on GitHub (pinned to 96fad776d2)