Scaffold-DbContext returns System.ArgumentNullException: Parameter name: proposedIdentifier in EFCore 2.0 when trying to pluralize

Liero

When I run command Scaffold-DbContext "Server=localhost;Database=MyDatabase;Integrated Security=true" Microsoft.EntityFrameworkCore.SqlServer

I get an error:

System.ArgumentNullException: Value cannot be null.
Parameter name: proposedIdentifier
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.Uniquifier(String proposedIdentifier, ICollection`1 existingIdentifiers)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateCSharpIdentifier(String identifier, ICollection`1 existingIdentifiers, Func`2 singularizePluralizer, Func`3 uniquifier)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUtilities.GenerateCSharpIdentifier(String identifier, ICollection`1 existingIdentifiers, Func`2 singularizePluralizer)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpNamer`1.GetName(T item)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpUniqueNamer`1.GetName(T item)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetEntityTypeName(DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.CreateFromDatabaseModel(DatabaseModel databaseModel, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Value cannot be null.
Parameter name: proposedIdentifier.

In my startup project I have:

public class CustomPluralizerDesignTimeServices : IDesignTimeServices
{
    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
        services.AddSingleton<IPluralizer, HumanizerToIPluralizerAdapter>();
    }
}

public class HumanizerToIPluralizerAdapter : IPluralizer
{
    public string Pluralize(string name) => name.Pluralize();

    public string Singularize(string name) => name.Singularize();
}

when I remove this code, the scaffolding works.

Dependencies:

  • DataAccess Project (.NET Standard 2.0)

    • Microsoft.EntityFrameworkCore.SqlServer 2.0
    • Microsoft.EntityFrameworkCore.Tools
    • Microsoft.VisualStudio.Web.CodeGeneration.Design
  • Startup Project (.NET CORE 2.0)

    • Microsoft.AspNetCore.All
bricelam

Looks like a bug in your IPluralizer implementation. Ensure it's not returning null or an empty string for some values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting an error in xamarin forms while inserting data: System.ArgumentNullException: 'Value cannot be null. Parameter name: cancel'

ArgumentNullException message without parameter name

ArgumentNullException occurring when trying to request authentication token

EFCore 1.1 Scaffold-DbContext provider error

Ninject StandardKernel System.ArgumentNullException: value cannot be null. Parameter name: path1

Azure App Service custom authentication getting System.ArgumentNullException: "Value cannot be null" "Parameter name: provider"

Error when trying to Scaffold a model

Autofac System.ArgumentNullException : Value cannot be null. Parameter name: context

How to pluralize collections when performing scaffold dbcontext?

Error Could not load type System.Data.OleDb.OleDbConnection from assembly System.Data when using Scaffold-DbContext, EntityFrameworkCore.Jet, .NetCore

Can EFCore Scaffold-DbContext generate custom Model names?

System.ArgumentNullException when GetDbContext in constructor

Scaffold-DbContext : A positional parameter cannot be found that accepts argument 'Models

System.ArgumentNullException: String reference not set to an instance of a String. Parameter name: s

Xamarin Forms OnConfigurationChanged - System.ArgumentNullException: Value cannot be null Parameter name: enumerable

System.ArgumentNullException: 'Value cannot be null. (Parameter 'connectionString')'

How to control DataAnnotations when using Scaffold-DbContext?

EFCore 5.0: Change tracker when DbContext is disposed (DbContext lifetime)

WebGL returns a error when trying to set aTextureCoord parameter

.Net BinaryFormater System.ArgumentNullException: Object Graph cannot be null. Parameter name: graph

How to understand this `System.ArgumentNullException` when trying to use `Concat` with `as`

ng-pluralize hide element when value is 0 (zero)

System.ArgumentNullException when creating a GUID

C# ODataQueryOptions with EF6 navigation property filters. System.ArgumentNullException : Value cannot be null. Parameter name: type

System.ArgumentNullException when awaiting IObservable

System.InvalidOperationException when trying use binding name as parameter in an azure function

IdentityServer4 System.ArgumentNullException: Value cannot be null. Parameter name: type when trying to refresh token

Error when get connection string: ArgumentNullException: Value cannot be null. Parameter name: connectionString

How do i scaffold DbContext with plural DbSet property names in as.net core EFCore 3?