{"record":{"id":"cee939ffd874b1f5","repo":"stride3d/stride","slug":"nameof-description-cannot-be-null-in-gettype-name","errorCode":null,"errorMessage":"[{nameof(Description)}] cannot be null in {GetType().Name}","messagePattern":"\\[(.+?)\\] cannot be null in (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs","lineNumber":227,"sourceCode":"\n    public void SetTag<T>(PropertyKey<T> key, T value)\n    {\n        Tags[key] = value;\n    }\n\n    protected virtual void ValidateParameters()\n    {\n        if (Name == null)\n        {\n            throw new InvalidOperationException($\"[{nameof(Name)}] cannot be null in {GetType().Name}\");\n        }\n        if (OutputDirectory == null && Description.Scope == TemplateScope.Session)\n        {\n            throw new InvalidOperationException($\"[{nameof(OutputDirectory)}] cannot be null in {GetType().Name}\");\n        }\n        if (Description == null)\n        {\n            throw new InvalidOperationException($\"[{nameof(Description)}] cannot be null in {GetType().Name}\");\n        }\n        if (Logger == null)\n        {\n            throw new InvalidOperationException($\"[{nameof(Logger)}] cannot be null in {GetType().Name}\");\n        }\n    }\n}\n","sourceCodeStart":209,"sourceCodeEnd":235,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs#L209-L235","documentation":"TemplateGeneratorParameters.ValidateParameters throws this InvalidOperationException when the Description property — the TemplateDescription describing which template to run — is null. Without a description the generator cannot know what files to produce or what scope applies, so validation rejects the parameters before any generation starts.","triggerScenarios":"Calling Validate() on any TemplateGeneratorParameters-derived object where Description was never assigned. Note the preceding OutputDirectory check dereferences Description, so a null Description with a null OutputDirectory throws the OutputDirectory error first; setting OutputDirectory (or a session-scope description) exposes this null-Description error.","commonSituations":"Manually constructed parameters in unit tests or tooling that only set Name/Logger; loading templates via a template provider that failed silently and returned no TemplateDescription; forgetting to assign Description while copying all other fields to a new parameters object.","solutions":["Assign a valid TemplateDescription to the Description property before calling Validate().","Load the description through the TemplateManager/template provider for the template Id you intend to run and check it is non-null.","If constructing descriptions by hand, ensure you pass it into the parameters object rather than only keeping it locally."],"exampleFix":"// before\nvar p = new SessionTemplateGeneratorParameters { Name = \"MyGame\", OutputDirectory = dir, Logger = logger, Session = session };\np.Validate(); // throws: Description null\n\n// after\nvar desc = TemplateManager.FindTemplate(templateId); // non-null TemplateDescription\nvar p = new SessionTemplateGeneratorParameters { Name = \"MyGame\", OutputDirectory = dir, Description = desc, Logger = logger, Session = session };\np.Validate();","handlingStrategy":"validation","validationCode":"if (p.Description == null)\n    throw new ArgumentException(\"TemplateGeneratorParameters.Description must be set to the resolved TemplateDescription before Validate().\");","typeGuard":"bool HasDescription(TemplateGeneratorParameters p) => p.Description is not null;","tryCatchPattern":"try { p.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.Description)))\n{\n    // re-resolve the template by Id and retry\n}","preventionTips":["Resolve the TemplateDescription via TemplateManager and null-check it before constructing parameters.","Include Description in every parameters object initializer, not just in copies.","When a template lookup fails, fail loudly instead of passing null through."],"tags":["csharp","null-argument","templates","validation"],"backgroundTag":"null-argument","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"}