stride3d/stride · error · InvalidOperationException
[ ] cannot be null in
Error message
[{nameof(Logger)}] cannot be null in {GetType().Name} What it means
TemplateGeneratorParameters.ValidateParameters throws this InvalidOperationException when the Logger property (a LoggerResult that collects generation diagnostics) is null. Stride's template generators report progress and errors through this logger, so validation requires one before running; it is the last mandatory field checked in the base ValidateParameters.
Solutions
- Assign a LoggerResult instance to the Logger property, e.g. new LoggerResult() or a suitable logger from your host application.
- In tests or headless tools, use a console or in-memory ILogger implementation deriving from LoggerResult to capture messages.
- If copying parameters manually, mirror the copy constructor and include Logger = parameters.Logger.
Example fix
// before
var p = new SessionTemplateGeneratorParameters { Name = "MyGame", OutputDirectory = dir, Description = desc, Session = session };
p.Validate(); // throws: Logger null
// after
var logger = new LoggerResult();
var p = new SessionTemplateGeneratorParameters { Name = "MyGame", OutputDirectory = dir, Description = desc, Logger = logger, Session = session };
p.Validate(); Defensive patterns
Strategy: validation
Validate before calling
if (p.Logger == null)
throw new ArgumentException("TemplateGeneratorParameters.Logger must be set to a LoggerResult before Validate()."); Type guard
bool HasLogger(TemplateGeneratorParameters p) => p.Logger is not null;
Try / catch
try { p.Validate(); }
catch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.Logger)))
{
// create a default LoggerResult and retry
} Prevention
- Always create a LoggerResult (console or in-memory) in tests and headless tools before generation.
- Copy parameters with the provided copy constructor, which carries Logger over automatically.
- Wire a single shared logger into all template generation calls in your application.
When it happens
Trigger: Calling Validate() on any TemplateGeneratorParameters-derived object with all other fields set but Logger never assigned — common in tests or headless tools where no editor logger is available.
Common situations: Unit tests exercising template generation without creating a logger; CLI tools skipping logger setup; refactors that dropped the Logger assignment when cloning parameters into a new parameters instance (the copy constructor does copy Logger, manual copies often don't).
Related errors
- [ ] cannot be null in
- [ ] cannot be null in
- [ ] cannot be null in
- [ ] cannot be null in
- [ ] cannot be null in
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/cb0611b8bc695dc2.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs:231
}
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)