{"record":{"id":"0832134b1aed8bb9","repo":"dotnet/efcore","slug":"the-property-property-of-the-argument-argume","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/CSharpModelGenerator.cs","lineNumber":58,"sourceCode":"    ///     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 string Language\n        => \"C#\";\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(\n        IModel model,\n        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        var contextTemplate = new CSharpDbContextGenerator { Host = host, Session = host.CreateSession() };\n        contextTemplate.Session.Add(\"Model\", model);\n        contextTemplate.Session.Add(\"Options\", options);\n        contextTemplate.Session.Add(\"NamespaceHint\", options.ContextNamespace ?? options.ModelNamespace);\n        contextTemplate.Session.Add(\"ProjectDefaultNamespace\", options.RootNamespace);\n        contextTemplate.Initialize();\n\n        var generatedCode = ProcessTemplate(contextTemplate);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs#L40-L76","documentation":"Thrown by CSharpModelGenerator.GenerateModel when ModelCodeGenerationOptions.ContextName is null. Scaffolding (reverse engineering) needs a class name for the generated DbContext, so a missing ContextName is treated as a bad argument and reported as ArgumentException via CoreStrings.ArgumentPropertyNull.","triggerScenarios":"Calling the scaffolding model generator (directly or via 'dotnet ef dbcontext scaffold' / Scaffold-DbContext) without setting the ContextName property on ModelCodeGenerationOptions.","commonSituations":"Programmatic scaffolding invocation that forgets ContextName; a custom tooling host that constructs ModelCodeGenerationOptions with defaults; misconfigured scaffolding options.","solutions":["Set options.ContextName to a valid class name before calling GenerateModel.","If invoking via CLI, pass --context <Name> (or use the default derived from the database).","Validate required options up front in your tooling wrapper."],"exampleFix":"// before\nvar options = new ModelCodeGenerationOptions();\n// after\nvar options = new ModelCodeGenerationOptions { ContextName = \"AppDbContext\" };","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(options.ContextName))\n    throw new ArgumentException(\"ContextName is required for scaffolding.\");\n// then call generator.GenerateModel(model, options);","typeGuard":"static bool IsScaffoldOptionsValid(ModelCodeGenerationOptions o) => !string.IsNullOrWhiteSpace(o.ContextName);","tryCatchPattern":"try { model = generator.GenerateModel(model, options); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ContextName\"))\n{ /* prompt the user for a context name and retry */ }","preventionTips":["Always set ContextName when constructing ModelCodeGenerationOptions.","Wrap scaffolding calls in an options validator.","Default ContextName from the database name when the user omits it."],"tags":["scaffolding","reverse-engineering","validation","options"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}