stride3d/stride · error · InvalidOperationException

[ ] cannot be null in

Error message

[{nameof(Name)}] cannot be null in {GetType().Name}

What it means

TemplateGeneratorParameters.ValidateParameters (base class) throws this InvalidOperationException when the Name property — the project/item name the template generator will use — is null. Name is mandatory for every template generation regardless of scope, so Validate() rejects the parameters early with a clear message naming the concrete parameters type.

Solutions

  1. Set the Name property to the desired non-null project/asset name before calling Validate().
  2. If Name comes from user input, check for null/empty and prompt before invoking the generator.
  3. Ensure any code path that copies parameters (e.g. new PackageTemplateGeneratorParameters(parameters, package)) preserves the source Name.

Example fix

// before
var p = new SessionTemplateGeneratorParameters { Description = desc, Logger = logger, Session = session };
p.Validate(); // throws: Name null

// after
var p = new SessionTemplateGeneratorParameters { Name = "MyGame", Description = desc, Logger = logger, Session = session };
p.Validate();
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(p.Name))
    throw new ArgumentException("Template generator parameters must have a Name before Validate().");

Type guard

bool HasName(TemplateGeneratorParameters p) => !string.IsNullOrWhiteSpace(p.Name);

Try / catch

try { p.Validate(); }
catch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.Name)))
{
    // surface 'name is required' to the user and reprompt
}

Prevention

When it happens

Trigger: Calling Validate() (or any ITemplateGenerator run that validates first) on a TemplateGeneratorParameters-derived object where Name was never assigned, or was explicitly set to null.

Common situations: Building parameters programmatically for a custom generator and forgetting Name; binding UI fields to parameters where the name textbox was left empty and null was propagated; deserializing parameters from config where the name field is absent.

Related errors


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

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs:219

    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="key"></param>
    /// <returns></returns>
    public bool HasTag<T>(PropertyKey<T> key)
    {
        return Tags.ContainsKey(key);
    }

    public void SetTag<T>(PropertyKey<T> key, T value)
    {
        Tags[key] = value;
    }

    protected virtual void ValidateParameters()
    {
        if (Name == null)
        {
            throw new InvalidOperationException($"[{nameof(Name)}] cannot be null in {GetType().Name}");
        }
        if (OutputDirectory == null && Description.Scope == TemplateScope.Session)
        {
            throw new InvalidOperationException($"[{nameof(OutputDirectory)}] cannot be null in {GetType().Name}");
        }
        if (Description == null)
        {
            throw new InvalidOperationException($"[{nameof(Description)}] cannot be null in {GetType().Name}");
        }
        if (Logger == null)
        {
            throw new InvalidOperationException($"[{nameof(Logger)}] cannot be null in {GetType().Name}");
        }
    }
}

View on GitHub (pinned to 96fad776d2)