{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Scaffolding/Internal/CSharpModelGenerator.cs#L40-L76","documentation":"Thrown in CSharpModelGenerator.GenerateModel (line 58) when ModelCodeGenerationOptions.ContextName is null. The scaffolding/reverse-engineering code generator needs a context class name to emit the DbContext file, so a null name is rejected with ArgumentException before any template runs. It is a contract violation on the options object passed to GenerateModel.","triggerScenarios":"Calling GenerateModel (directly or via ScaffoldModel/ReverseEngineer) with options.ContextName left null. The check `if (options.ContextName == null)` fires and throws ArgumentException referencing CoreStrings.ArgumentPropertyNull(nameof(options.ContextName), nameof(options)).","commonSituations":"Programmatic scaffolding where the caller forgot to set ContextName on ModelCodeGenerationOptions. A wrapper/wizard that builds options incrementally and skips the name. Passing default(options)-style object. Note: ReverseEngineerScaffolder will derive a default ContextName, so this typically surfaces only when calling the code generator directly.","solutions":["Set options.ContextName to a valid, non-null context class name before calling GenerateModel.","If scaffolding programmatically, derive a default name (e.g. from the database name) and assign it, mirroring ReverseEngineerScaffolder's behavior.","Validate all required ModelCodeGenerationOptions fields before invoking the generator."],"exampleFix":"// before\nvar options = new ModelCodeGenerationOptions { ConnectionString = cs };\nmodelGenerator.GenerateModel(model, options); // throws: ContextName null\n\n// after\nvar options = new ModelCodeGenerationOptions\n{\n    ConnectionString = cs,\n    ContextName = \"ShopContext\"\n};\nmodelGenerator.GenerateModel(model, options);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(options.ContextName))\n    throw new InvalidOperationException(\"ContextName is required.\");\n// or set a default before calling the generator","typeGuard":null,"tryCatchPattern":"try { generator.GenerateModel(model, options); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"ContextName\"))\n{ /* set options.ContextName and retry */ }","preventionTips":["Always set ContextName on ModelCodeGenerationOptions before GenerateModel.","Centralize options construction in a helper that enforces required fields."],"tags":["ef-core","scaffolding","validation","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}