stride3d/stride · error · ArgumentNullException
ArgumentNullException: viewModel
Error message
ArgumentNullException: viewModel
What it means
Argument-null validation in the ItemTemplatesWindow constructor: the viewModel parameter (the AssetTemplatesViewModel supplying the template list to display) is null. The window cannot render the asset template selection dialog without a view model, so the constructor rejects the call rather than creating a non-functional dialog.
Solutions
- Construct a valid AssetTemplatesViewModel before creating the window
- Check the factory/di result for null and fail earlier with a meaningful message
- Show an error dialog instead of opening the window when no view model exists
Example fix
// before
var window = new ItemTemplatesWindow(CreateViewModel());
// after
var vm = CreateViewModel();
if (vm == null) throw new InvalidOperationException("Failed to create asset templates view model");
var window = new ItemTemplatesWindow(vm); Defensive patterns
Strategy: validation
Validate before calling
if (viewModel == null) { ShowError("Templates view model unavailable"); return; }
var window = new ItemTemplatesWindow(viewModel); Type guard
static bool HasViewModel([NotNullWhen(true)] AssetTemplatesViewModel? vm) => vm is not null;
Try / catch
try { var w = new ItemTemplatesWindow(vm); w.ShowDialog(); } catch (ArgumentNullException ex) { logger.LogError(ex, "Cannot open templates window without a view model"); } Prevention
- Resolve the view model before constructing its window
- Fail fast with a user-visible message instead of passing null down
- Keep view-model construction and window construction adjacent in code
When it happens
Trigger: new ItemTemplatesWindow(viewModel) with viewModel == null, e.g. a failed view-model resolution passed straight into the window.
Common situations: Wiring the Add Assets dialog in the editor when the view model factory returned null (dependency resolution failure or null templates earlier in the pipeline).
Related errors
- entity must contain a non-null asset entity.
- ArgumentNullException: element
- Value cannot be null. (Parameter 'location')
- Value cannot be null. (Parameter 'asset')
- Value cannot be null. (Parameter 'value')
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c696958c655ada07.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/Components/AddAssets/View/ItemTemplatesWindow.xaml.cs:20
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Stride.Core.Assets.Editor.Components.TemplateDescriptions.ViewModels;
using Stride.Core.Assets.Editor.Services;
namespace Stride.Core.Assets.Editor.Components.AddAssets.View
{
/// <summary>
/// Interaction logic for AssetTemplatesWindow.xaml
/// </summary>
public partial class ItemTemplatesWindow : IItemTemplateDialog
{
public ItemTemplatesWindow(AssetTemplatesViewModel viewModel)
{
if (viewModel == null) throw new ArgumentNullException(nameof(viewModel));
InitializeComponent();
ViewModel = viewModel;
Loaded += OnLoaded;
}
public AssetTemplatesViewModel ViewModel { get { return (AssetTemplatesViewModel)DataContext; } set { DataContext = value; } }
public ITemplateDescriptionViewModel SelectedTemplate { get; private set; }
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonDown(e);
if (IsMouseOverWindow(e))
{
// Defer the validation so the list box has time to update the selected template (we are fired before it because it is the preview event).
Dispatcher.InvokeAsync(Validate);
}
}View on GitHub (pinned to 96fad776d2)