stride3d/stride · error · InvalidOperationException
[ . ] must be in
Error message
[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Session} in {GetType().Name} What it means
TemplateGeneratorParameters.ValidateParameters enforces that a generator's Description.Scope is TemplateScope.Session (and that Session is non-null). This InvalidOperationException is thrown when a generator whose type derives from this parameters class is invoked with a Description configured for a different scope.
Solutions
- Set Description.Scope = TemplateScope.Session on the generator's parameters/template description
- If a different scope is intended, derive from the appropriate parameters/generator base class instead of the Session-scoped one
- Check the template's .tpl/YAML description for a mismatched Scope value and fix it
- Also ensure Session is assigned, since the same ValidateParameters checks it next
Example fix
// before
Description = new TemplateDescription { Name = "MySessionTpl", Scope = TemplateScope.Package }
// after
Description = new TemplateDescription { Name = "MySessionTpl", Scope = TemplateScope.Session } Defensive patterns
Strategy: validation
Validate before calling
if (parameters.Description.Scope != TemplateScope.Session) throw new InvalidOperationException("Session-scoped generator requires TemplateScope.Session");
if (parameters.Session == null) throw new InvalidOperationException("Session must be set"); Type guard
bool IsValidSessionTemplateParams(TemplateGeneratorParameters p) => p.Description?.Scope == TemplateScope.Session && p.Session != null;
Try / catch
try { generator.Run(parameters); } catch (InvalidOperationException ex) when (ex.Message.Contains("Scope")) { log.Error($"Template scope misconfigured: {ex.Message}"); throw; } Prevention
- When copying templates, verify Description.Scope matches the generator base class
- Add a startup sanity check of all registered template descriptions
- Document required Scope on custom generator base classes
When it happens
Trigger: Invoking a template generator whose TemplateGeneratorParameters.Description.Scope was set to something other than TemplateScope.Session (e.g. Package scope) — typically from a custom template definition or a copy of an existing template whose scope was not updated.
Common situations: Writing a custom session-level template by copying a package-level template's Description without changing Scope; editing .tpl template descriptions by hand; upgrading Stride and introducing new scopes that conflict with old descriptions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c916ab315192d1a7.
Report an issue: GitHub.
Appendix: source
Thrown at sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs:23
using Stride.Core.IO;
namespace Stride.Core.Assets.Templates;
public sealed class SessionTemplateGeneratorParameters : TemplateGeneratorParameters
{
/// <summary>
/// Gets or sets the current session.
/// </summary>
/// <value>The session.</value>
public PackageSession Session { get; set; }
protected override void ValidateParameters()
{
base.ValidateParameters();
if (Description.Scope != TemplateScope.Session)
{
throw new InvalidOperationException($"[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Session} in {GetType().Name}");
}
if (Session == null)
{
throw new InvalidOperationException($"[{nameof(Session)}] cannot be null in {GetType().Name}");
}
}
}
public class PackageTemplateGeneratorParameters : TemplateGeneratorParameters
{
public PackageTemplateGeneratorParameters()
{
}
public PackageTemplateGeneratorParameters(TemplateGeneratorParameters parameters, Package package)
: base(parameters)
{
Package = package;View on GitHub (pinned to 96fad776d2)