{"record":{"id":"62df001cd05971d4","repo":"stride3d/stride","slug":"nameof-name-cannot-be-null-in-gettype-name","errorCode":null,"errorMessage":"[{nameof(Name)}] 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":219,"sourceCode":"    /// </summary>\n    /// <typeparam name=\"T\"></typeparam>\n    /// <param name=\"key\"></param>\n    /// <returns></returns>\n    public bool HasTag<T>(PropertyKey<T> key)\n    {\n        return Tags.ContainsKey(key);\n    }\n\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":201,"sourceCodeEnd":235,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs#L201-L235","documentation":"TemplateGeneratorParameters.ValidateParameters (base class) throws this InvalidOperationException when the Name property — the project/item name the template generator will use — is null. Name is mandatory for every template generation regardless of scope, so Validate() rejects the parameters early with a clear message naming the concrete parameters type.","triggerScenarios":"Calling Validate() (or any ITemplateGenerator run that validates first) on a TemplateGeneratorParameters-derived object where Name was never assigned, or was explicitly set to null.","commonSituations":"Building parameters programmatically for a custom generator and forgetting Name; binding UI fields to parameters where the name textbox was left empty and null was propagated; deserializing parameters from config where the name field is absent.","solutions":["Set the Name property to the desired non-null project/asset name before calling Validate().","If Name comes from user input, check for null/empty and prompt before invoking the generator.","Ensure any code path that copies parameters (e.g. new PackageTemplateGeneratorParameters(parameters, package)) preserves the source Name."],"exampleFix":"// before\nvar p = new SessionTemplateGeneratorParameters { Description = desc, Logger = logger, Session = session };\np.Validate(); // throws: Name null\n\n// after\nvar p = new SessionTemplateGeneratorParameters { Name = \"MyGame\", Description = desc, Logger = logger, Session = session };\np.Validate();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(p.Name))\n    throw new ArgumentException(\"Template generator parameters must have a Name before Validate().\");","typeGuard":"bool HasName(TemplateGeneratorParameters p) => !string.IsNullOrWhiteSpace(p.Name);","tryCatchPattern":"try { p.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.Name)))\n{\n    // surface 'name is required' to the user and reprompt\n}","preventionTips":["Validate user-supplied names in the UI/CLI before constructing parameters.","Use object initializers that include Name for every parameters instance.","Treat Name as a required field in any code that builds parameters from config or serialization."],"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"}