{"record":{"id":"508d45b3929bad1d","repo":"stride3d/stride","slug":"nameof-description-nameof-description-scope-must-be-508d45","errorCode":null,"errorMessage":"[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Package} 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":55,"sourceCode":"\n    public PackageTemplateGeneratorParameters(TemplateGeneratorParameters parameters, Package package)\n        : base(parameters)\n    {\n        Package = package;\n    }\n    /// <summary>\n    /// Gets or sets the package in which to execute this template\n    /// </summary>\n    /// <value>The package.</value>\n    public Package Package { get; set; }\n\n    protected override void ValidateParameters()\n    {\n        base.ValidateParameters();\n\n        if (Description.Scope != TemplateScope.Package && GetType() == typeof(PackageTemplateGeneratorParameters))\n        {\n            throw new InvalidOperationException($\"[{nameof(Description)}.{nameof(Description.Scope)}] must be {TemplateScope.Package} in {GetType().Name}\");\n        }\n        if (Package == null)\n        {\n            throw new InvalidOperationException($\"[{nameof(Package)}] cannot be null in {GetType().Name}\");\n        }\n    }\n}\n\npublic class AssetTemplateGeneratorParameters : PackageTemplateGeneratorParameters\n{\n    public AssetTemplateGeneratorParameters(UDirectory targetLocation, IEnumerable<UFile>? sourceFiles = null)\n    {\n        TargetLocation = targetLocation;\n        SourceFiles = [];\n        if (sourceFiles != null)\n            SourceFiles.AddRange(sourceFiles);\n    }\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs#L37-L73","documentation":"PackageTemplateGeneratorParameters.ValidateParameters throws this InvalidOperationException when the template Description.Scope is not TemplateScope.Package while the concrete parameters type is exactly PackageTemplateGeneratorParameters. The scope recorded in the TemplateDescription must match the parameters type used, otherwise the generator would run a package-level template with the wrong assumptions; the check is skipped for derived types like AssetTemplateGeneratorParameters which enforce their own scope.","triggerScenarios":"Calling Validate() on a PackageTemplateGeneratorParameters instance whose Description was loaded from a template whose TemplateDescription.Scope is Session or Asset (or left at a non-Package default).","commonSituations":"Mixing up template description files when wiring custom generators: pointing a package generator at an asset template's .sdtpl description; a typo or refactor changing the Scope value in the template description; reusing one Description object across differently-scoped parameters.","solutions":["Set the template description's Scope property to TemplateScope.Package (or fix the .sdtpl/description file) so it matches PackageTemplateGeneratorParameters.","If the template is really asset- or session-scoped, use AssetTemplateGeneratorParameters or SessionTemplateGeneratorParameters instead.","Check which TemplateDescription you assigned to the Description property — it likely belongs to a different template."],"exampleFix":"// before\nvar p = new PackageTemplateGeneratorParameters(baseParams, package)\n{\n    Description = assetTemplateDescription // Scope == TemplateScope.Asset\n};\np.Validate(); // throws\n\n// after\nassetTemplateDescription.Scope = TemplateScope.Package; // or use the matching description\nvar p = new PackageTemplateGeneratorParameters(baseParams, package)\n{\n    Description = packageTemplateDescription // Scope == TemplateScope.Package\n};\np.Validate();","handlingStrategy":"validation","validationCode":"if (p is PackageTemplateGeneratorParameters pp && pp.Description?.Scope != TemplateScope.Package)\n    throw new InvalidOperationException($\"Template '{pp.Description?.Id}' scope {pp.Description?.Scope} does not match PackageTemplateGeneratorParameters.\");","typeGuard":"bool ScopeMatches(PackageTemplateGeneratorParameters p) => p.Description?.Scope == TemplateScope.Package;","tryCatchPattern":"try { p.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateDescription.Scope)))\n{\n    // fix the template description Scope or pick the right parameters type\n}","preventionTips":["Keep each template's .sdtpl description Scope value in sync with the parameters type you feed it.","Never reuse one TemplateDescription across differently-scoped generators.","Assert Description.Scope immediately after loading the template description."],"tags":["csharp","invalid-enum-value","templates","validation"],"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"}