{"record":{"id":"cb4509841760610d","repo":"dotnet/efcore","slug":"the-property-property-of-the-argument-argume-cb4509","errorCode":null,"errorMessage":"The property '{property}' of the argument '{argument}' cannot be 'null'.","messagePattern":"The property '(.+?)' of the argument '(.+?)' cannot be 'null'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/TextTemplatingModelGenerator.cs","lineNumber":80,"sourceCode":"        var hasEntityTypeTemplate = File.Exists(Path.Combine(projectDir, TemplatesDirectory, EntityTypeTemplate));\n        var hasConfigurationTemplate = File.Exists(Path.Combine(projectDir, TemplatesDirectory, EntityTypeConfigurationTemplate));\n\n        return hasConfigurationTemplate && !hasContextTemplate\n            ? throw new OperationException(DesignStrings.NoContextTemplateButConfiguration)\n            : hasContextTemplate || hasEntityTypeTemplate || hasConfigurationTemplate;\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOptions options)\n    {\n        if (options.ContextName == null)\n        {\n            throw new ArgumentException(\n                CoreStrings.ArgumentPropertyNull(nameof(options.ContextName), nameof(options)), nameof(options));\n        }\n\n        if (options.ConnectionString == null)\n        {\n            throw new ArgumentException(\n                CoreStrings.ArgumentPropertyNull(nameof(options.ConnectionString), nameof(options)), nameof(options));\n        }\n\n        var host = new TextTemplatingEngineHost(_serviceProvider)\n        {\n            Session =\n            {\n                { \"Model\", model },\n                { \"Options\", options },\n                { \"NamespaceHint\", options.ContextNamespace ?? options.ModelNamespace },\n                { \"ProjectDefaultNamespace\", options.RootNamespace }\n            }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/TextTemplatingModelGenerator.cs#L62-L98","documentation":"Thrown by the T4-based model generator when ModelCodeGenerationOptions.ContextName is null at code-generation time. The context name is required to name the generated DbContext class and its output file, so a null value is treated as an invalid argument rather than defaulting silently.","triggerScenarios":"Calling TextTemplatingModelGenerator.GenerateModel(model, options) with options.ContextName == null. Typically only reachable when invoking the T4 generator programmatically rather than through the scaffold command (which derives a context name first).","commonSituations":"Programmatic scaffolding where the caller forgot to set ContextName, or a custom design-time workflow that bypasses the default name derivation in ReverseEngineerScaffolder.","solutions":["Set options.ContextName to a valid C# identifier before calling GenerateModel.","Use the higher-level ScaffoldModel API, which derives a default context name from the database name when ContextName is empty.","Pass --context <Name> on `dotnet ef dbcontext scaffold` to set it explicitly."],"exampleFix":"// before\nvar options = new ModelCodeGenerationOptions();\nsg.GenerateModel(model, options);\n// after\nvar options = new ModelCodeGenerationOptions { ContextName = \"ShopContext\" };\nsg.GenerateModel(model, options);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(options.ContextName))\n    options.ContextName = \"AppDbContext\";\n// or fail fast\nArgumentException.ThrowIfNullOrWhiteSpace(options.ContextName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set ContextName when calling TextTemplatingModelGenerator directly.","Prefer the higher-level ScaffoldModel API which derives a default name.","Centralize option construction in a factory method to enforce required fields."],"tags":["t4","templating","scaffolding","design-time","validation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}