stride3d/stride · error · ArgumentNullException
ArgumentNullException: generator
Error message
ArgumentNullException: generator
What it means
RunTemplateGeneratorSafe runs an ITemplateGenerator<TParameters> safely with progress reporting, and validates its arguments up front. It throws ArgumentNullException when the generator parameter is null — no template generator was supplied to run.
Solutions
- Pass a non-null ITemplateGenerator<TParameters> instance
- Verify the generator factory/resolution logic never returns null for known templates
- Check that the template being generated has a registered generator implementation
Example fix
// before
await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress);
// after
if (generator == null) throw new InvalidOperationException($"No generator found for template '{parameters?.TemplateId}'");
await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress); Defensive patterns
Strategy: validation
Validate before calling
if (generator == null) throw new ArgumentException("No template generator resolved for this template", nameof(generator)); Type guard
bool CanRun<T>(ITemplateGenerator<T> g) where T : TemplateGeneratorParameters => g != null;
Try / catch
try { await RunTemplateGeneratorSafe(generator, parameters, progress); } catch (ArgumentNullException ex) when (ex.ParamName == "generator") { /* report missing generator for template */ } Prevention
- Resolve generators through a registry that throws a descriptive error on unknown templates
- Never let generator factories return null — fail with a template-id-bearing message
- Unit-test generator resolution for every shipped template
When it happens
Trigger: Calling TemplateGeneratorHelper.RunTemplateGeneratorSafe(null, parameters, workProgress), e.g. when the generator factory or template resolution returned null before the call.
Common situations: Template descriptor not matching any registered generator; DI/factory returning null for an unknown or misconfigured template; refactoring that removed a generator registration.
Related errors
- ArgumentNullException: parameters
- builder
- Cannot add a null UIElement to the children list.
- compilerParameters
- gameSettings
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/e45cfd61482f1fc9.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/TemplateGeneratorHelper.cs:24
using Stride.Core.Assets.Editor.ViewModel.Progress;
using Stride.Core.Assets.Templates;
using Stride.Core.Translation;
namespace Stride.Core.Assets.Editor.Components.TemplateDescriptions
{
internal static class TemplateGeneratorHelper
{
/// <summary>
/// Invokes the given template generator safely. The generator will be prepared on the calling thread, and run from
/// a task. This methods will catch and log all exceptions occurring during the template generation.
/// </summary>
/// <param name="generator">The template generator to run.</param>
/// <param name="parameters">The parameters for the template generator.</param>
/// <param name="workProgress">The view model used to report progress.</param>
/// <returns>A task that completes when the template generator has finished to run.</returns>
internal static async Task<bool> RunTemplateGeneratorSafe<TParameters>(ITemplateGenerator<TParameters> generator, TParameters parameters, WorkProgressViewModel workProgress) where TParameters : TemplateGeneratorParameters
{
if (generator == null) throw new ArgumentNullException(nameof(generator));
if (parameters == null) throw new ArgumentNullException(nameof(parameters));
var success = false;
try
{
success = await generator.PrepareForRun(parameters);
if (!success)
{
// If the preparation failed without error, it means that the user cancelled the operation.
if (!parameters.Logger.HasErrors)
parameters.Logger.Info(Tr._p("Log", "Operation cancelled."));
return false;
}
}
catch (Exception e)
{
parameters.Logger.Error(Tr._p("Log", "An exception occurred while generating the template."), e);
}View on GitHub (pinned to 96fad776d2)