stride3d/stride · error · InvalidOperationException

[ ] cannot be null in

Error message

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

What it means

TemplateGeneratorParameters.ValidateParameters throws this InvalidOperationException when OutputDirectory is null while the template Description.Scope is TemplateScope.Session. Session-scoped generation (e.g. creating a whole new project/solution) needs an explicit output directory because there is no existing package location to write into; other scopes may derive the output from the package and are exempt.

Solutions

  1. Set OutputDirectory to a valid UDirectory path before calling Validate().
  2. If the template actually runs inside an existing package (Package/Asset scope), verify Description.Scope is not Session — the check then no longer applies.
  3. In CLI tools, make the output path a required argument and populate OutputDirectory from it.

Example fix

// before
var p = new SessionTemplateGeneratorParameters { Name = "MyGame", Description = sessionDesc /* Scope = Session */, Logger = logger, Session = session };
p.Validate(); // throws

// after
p.OutputDirectory = new UDirectory(@"D:\Projects\MyGame");
p.Validate();
Defensive patterns

Strategy: validation

Validate before calling

if (p.Description?.Scope == TemplateScope.Session && p.OutputDirectory == null)
    throw new ArgumentException("OutputDirectory is required for session-scope template generation.");

Type guard

bool HasOutputDirForSession(TemplateGeneratorParameters p) => p.Description?.Scope != TemplateScope.Session || p.OutputDirectory is not null;

Try / catch

try { p.Validate(); }
catch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.OutputDirectory)))
{
    // ask the user for / default an output directory and retry
}

Prevention

When it happens

Trigger: Calling Validate() on session-scope parameters (Description.Scope == TemplateScope.Session, e.g. SessionTemplateGeneratorParameters) with OutputDirectory left null — typically when generating a new project without specifying where to create it.

Common situations: Headless/CLI project generators that accept a path argument the user omitted; the editor normally computes OutputDirectory from the 'new project' dialog and CLI reproductions skip it; a refactor that stopped copying OutputDirectory into a new parameters object.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

    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)