{"record":{"id":"e45cfd61482f1fc9","repo":"stride3d/stride","slug":"argumentnullexception-generator","errorCode":null,"errorMessage":"ArgumentNullException: generator","messagePattern":"ArgumentNullException: generator","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/TemplateGeneratorHelper.cs","lineNumber":24,"sourceCode":"using Stride.Core.Assets.Editor.ViewModel.Progress;\nusing Stride.Core.Assets.Templates;\nusing Stride.Core.Translation;\n\nnamespace Stride.Core.Assets.Editor.Components.TemplateDescriptions\n{\n    internal static class TemplateGeneratorHelper\n    {\n        /// <summary>\n        /// Invokes the given template generator safely. The generator will be prepared on the calling thread, and run from\n        /// a task. This methods will catch and log all exceptions occurring during the template generation.\n        /// </summary>\n        /// <param name=\"generator\">The template generator to run.</param>\n        /// <param name=\"parameters\">The parameters for the template generator.</param>\n        /// <param name=\"workProgress\">The view model used to report progress.</param>\n        /// <returns>A task that completes when the template generator has finished to run.</returns>\n        internal static async Task<bool> RunTemplateGeneratorSafe<TParameters>(ITemplateGenerator<TParameters> generator, TParameters parameters, WorkProgressViewModel workProgress) where TParameters : TemplateGeneratorParameters\n        {\n            if (generator == null) throw new ArgumentNullException(nameof(generator));\n            if (parameters == null) throw new ArgumentNullException(nameof(parameters));\n            var success = false;\n            try\n            {\n                success = await generator.PrepareForRun(parameters);\n                if (!success)\n                {\n                    // If the preparation failed without error, it means that the user cancelled the operation.\n                    if (!parameters.Logger.HasErrors)\n                        parameters.Logger.Info(Tr._p(\"Log\", \"Operation cancelled.\"));\n\n                    return false;\n                }\n            }\n            catch (Exception e)\n            {\n                parameters.Logger.Error(Tr._p(\"Log\", \"An exception occurred while generating the template.\"), e);\n            }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/Components/TemplateDescriptions/TemplateGeneratorHelper.cs#L6-L42","documentation":"RunTemplateGeneratorSafe runs an ITemplateGenerator<TParameters> safely with progress reporting, and validates its arguments up front. It throws ArgumentNullException when the generator parameter is null — no template generator was supplied to run.","triggerScenarios":"Calling TemplateGeneratorHelper.RunTemplateGeneratorSafe(null, parameters, workProgress), e.g. when the generator factory or template resolution returned null before the call.","commonSituations":"Template descriptor not matching any registered generator; DI/factory returning null for an unknown or misconfigured template; refactoring that removed a generator registration.","solutions":["Pass a non-null ITemplateGenerator<TParameters> instance","Verify the generator factory/resolution logic never returns null for known templates","Check that the template being generated has a registered generator implementation"],"exampleFix":"// before\nawait TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress);\n// after\nif (generator == null) throw new InvalidOperationException($\"No generator found for template '{parameters?.TemplateId}'\");\nawait TemplateGeneratorHelper.RunTemplateGeneratorSafe(generator, parameters, progress);","handlingStrategy":"validation","validationCode":"if (generator == null) throw new ArgumentException(\"No template generator resolved for this template\", nameof(generator));","typeGuard":"bool CanRun<T>(ITemplateGenerator<T> g) where T : TemplateGeneratorParameters => g != null;","tryCatchPattern":"try { await RunTemplateGeneratorSafe(generator, parameters, progress); } catch (ArgumentNullException ex) when (ex.ParamName == \"generator\") { /* report missing generator for template */ }","preventionTips":["Resolve generators through a registry that throws a descriptive error on unknown templates","Never let generator factories return null — fail with a template-id-bearing message","Unit-test generator resolution for every shipped template"],"tags":["null-argument","template-generator","csharp"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}