{"record":{"id":"c916ab315192d1a7","repo":"stride3d/stride","slug":"nameof-description-nameof-description-scope-must-be","errorCode":null,"errorMessage":"[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Session} in {GetType().Name}","messagePattern":"\\[(.+?)\\.(.+?)\\] must be (.+?) in (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs","lineNumber":23,"sourceCode":"using Stride.Core.IO;\n\nnamespace Stride.Core.Assets.Templates;\n\npublic sealed class SessionTemplateGeneratorParameters : TemplateGeneratorParameters\n{\n    /// <summary>\n    /// Gets or sets the current session.\n    /// </summary>\n    /// <value>The session.</value>\n    public PackageSession Session { get; set; }\n\n    protected override void ValidateParameters()\n    {\n        base.ValidateParameters();\n\n        if (Description.Scope != TemplateScope.Session)\n        {\n            throw new InvalidOperationException($\"[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Session} in {GetType().Name}\");\n        }\n        if (Session == null)\n        {\n            throw new InvalidOperationException($\"[{nameof(Session)}] cannot be null in {GetType().Name}\");\n        }\n    }\n}\n\npublic class PackageTemplateGeneratorParameters : TemplateGeneratorParameters\n{\n    public PackageTemplateGeneratorParameters()\n    {\n    }\n\n    public PackageTemplateGeneratorParameters(TemplateGeneratorParameters parameters, Package package)\n        : base(parameters)\n    {\n        Package = package;","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs#L5-L41","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nDescription = new TemplateDescription { Name = \"MySessionTpl\", Scope = TemplateScope.Package }\n// after\nDescription = new TemplateDescription { Name = \"MySessionTpl\", Scope = TemplateScope.Session }","handlingStrategy":"validation","validationCode":"if (parameters.Description.Scope != TemplateScope.Session) throw new InvalidOperationException(\"Session-scoped generator requires TemplateScope.Session\");\nif (parameters.Session == null) throw new InvalidOperationException(\"Session must be set\");","typeGuard":"bool IsValidSessionTemplateParams(TemplateGeneratorParameters p) => p.Description?.Scope == TemplateScope.Session && p.Session != null;","tryCatchPattern":"try { generator.Run(parameters); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Scope\")) { log.Error($\"Template scope misconfigured: {ex.Message}\"); throw; }","preventionTips":["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"],"tags":["templates","validation","invalid-operation","scope"],"backgroundTag":"invalid-enum-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}