{"record":{"id":"3ab5aabdbc52a332","repo":"stride3d/stride","slug":"nameof-outputdirectory-cannot-be-null-in-gettype-name","errorCode":null,"errorMessage":"[{nameof(OutputDirectory)}] 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":223,"sourceCode":"    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":205,"sourceCodeEnd":235,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/Templates/TemplateGeneratorParameters.cs#L205-L235","documentation":"TemplateGeneratorParameters.ValidateParameters throws this InvalidOperationException when OutputDirectory is null while the template Description.Scope is TemplateScope.Session. Session-scoped generation (e.g. creating a whole new project/solution) needs an explicit output directory because there is no existing package location to write into; other scopes may derive the output from the package and are exempt.","triggerScenarios":"Calling Validate() on session-scope parameters (Description.Scope == TemplateScope.Session, e.g. SessionTemplateGeneratorParameters) with OutputDirectory left null — typically when generating a new project without specifying where to create it.","commonSituations":"Headless/CLI project generators that accept a path argument the user omitted; the editor normally computes OutputDirectory from the 'new project' dialog and CLI reproductions skip it; a refactor that stopped copying OutputDirectory into a new parameters object.","solutions":["Set OutputDirectory to a valid UDirectory path before calling Validate().","If the template actually runs inside an existing package (Package/Asset scope), verify Description.Scope is not Session — the check then no longer applies.","In CLI tools, make the output path a required argument and populate OutputDirectory from it."],"exampleFix":"// before\nvar p = new SessionTemplateGeneratorParameters { Name = \"MyGame\", Description = sessionDesc /* Scope = Session */, Logger = logger, Session = session };\np.Validate(); // throws\n\n// after\np.OutputDirectory = new UDirectory(@\"D:\\Projects\\MyGame\");\np.Validate();","handlingStrategy":"validation","validationCode":"if (p.Description?.Scope == TemplateScope.Session && p.OutputDirectory == null)\n    throw new ArgumentException(\"OutputDirectory is required for session-scope template generation.\");","typeGuard":"bool HasOutputDirForSession(TemplateGeneratorParameters p) => p.Description?.Scope != TemplateScope.Session || p.OutputDirectory is not null;","tryCatchPattern":"try { p.Validate(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(nameof(TemplateGeneratorParameters.OutputDirectory)))\n{\n    // ask the user for / default an output directory and retry\n}","preventionTips":["Make the output path a required CLI/UI argument for new-project generation.","Default OutputDirectory to a sensible root (e.g. current directory or a configured projects folder) when unspecified.","Check Description.Scope early to know which fields your parameters type requires."],"tags":["csharp","null-argument","templates","validation"],"backgroundTag":"missing-required-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"}