stride3d/stride · error · ArgumentNullException

ArgumentNullException: parameters

Error message

ArgumentNullException: parameters

What it means

RunTemplateGeneratorSafe validates the parameters argument and throws ArgumentNullException when it is null. The generator cannot PrepareForRun without a TParameters instance derived from TemplateGeneratorParameters.

Solutions

  1. Construct and pass a valid TemplateGeneratorParameters-derived object
  2. Fail earlier with a clear message if the wizard/validation produces null parameters
  3. Null-check parameters at the calling layer before invoking the helper

Example fix

// before
await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress);
// after
if (parameters == null) return false; // or surface validation error to the user
await TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress);
Defensive patterns

Strategy: validation

Validate before calling

if (parameters == null) throw new ArgumentException("Template generator parameters were not built", nameof(parameters));

Type guard

bool ValidParameters(TemplateGeneratorParameters p) => p != null && p.IsValid();

Try / catch

try { await RunTemplateGeneratorSafe(generator, parameters, progress); } catch (ArgumentNullException ex) when (ex.ParamName == "parameters") { /* surface parameter-build failure to the user */ }

Prevention

When it happens

Trigger: Calling RunTemplateGeneratorSafe(generator, null, workProgress) — commonly when the TemplateGeneratorParameters object failed to build (e.g. empty/invalid project creation wizard input) and null was passed through.

Common situations: New-project wizard producing null parameters on invalid input; deserialization of template settings failing silently; caller skipping parameters construction on an error path.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/d736bf7b27dab744. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/TemplateGeneratorHelper.cs:25

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)