Efcore: System.ArgumentException: The argument 'name' cannot be null, empty or contain only whitespace. (Parameter 'name')

Created on 17 Feb 2020  路  10Comments  路  Source: dotnet/efcore

I have several Entities in my datacontext and when I try to run a query against them I get the following error and I am not sure what to look at but I started out with the Table attribute since the message stack trace starts out TableAttribute the declaration of that attribute is correct. Not sure what to look at next and hoping someone has a suggestion.

System.ArgumentException: The argument 'name' cannot be null, empty or contain only whitespace. (Parameter 'name')

Got Exceptions? Include both the message and the stack trace

   System.ArgumentException: The argument 'name' cannot be null, empty or contain only whitespace. (Parameter 'name')
  Stack Trace: 
    TableAttribute.ctor(String name)
    CustomAttribute._CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
    CustomAttribute.CreateCaObject(RuntimeModule module, RuntimeType type, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
    CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
    CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
    RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
    Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
    CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean inherit)
    EntityTypeAttributeConventionBase`1.ProcessEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder, IConventionContext`1 context)
    ImmediateConventionScope.OnEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder)
    RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode node)
    OnEntityTypeAddedNode.Accept(ConventionVisitor visitor)
    ConventionVisitor.Visit(ConventionNode node)
    ConventionVisitor.VisitConventionScope(ConventionScope node)
    ConventionBatch.Run()
    ConventionBatch.Dispose()
    ImmediateConventionScope.OnModelInitialized(IConventionModelBuilder modelBuilder)
    ConventionDispatcher.OnModelInitialized(IConventionModelBuilder modelBuilder)
    Model.ctor(ConventionSet conventions)
    ModelBuilder.ctor(ConventionSet conventions)
    ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
    ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
    DbContextServices.CreateModel()
    DbContextServices.get_Model()
    <>c.<TryAddCoreServices>b__7_3(IServiceProvider p)
    CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
    CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
    CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
    CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
    CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
    CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
    CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
    CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
    CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
    CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
    CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
    <>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
    ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
    ServiceProviderEngineScope.GetService(Type serviceType)
    ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
    ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
    DbContext.get_DbContextDependencies()
    DbContext.get_InternalServiceProvider()
    DbContext.get_DbContextDependencies()
    DbContext.get_Model()
    InternalDbSet`1.get_EntityType()
    InternalDbSet`1.CheckState()
    InternalDbSet`1.get_EntityQueryable()
    IQueryable.get_Provider()
    EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
    EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, CancellationToken cancellationToken)
    EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
    UnitTests.Items() line 468
    ThreadOperations.ExecuteWithAbortSafety(Action action)

Further technical details

EF Core version: 3.1.1
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.1.1)
Operating system: Windows 10 1909
IDE: (e.g. Visual Studio 2019 16.4.5)

closed-question customer-reported

All 10 comments

the declaration of that attribute is correct

The stack trace is saying that the name argument passed to the attribute is null or empty. Can you post code showing how you are using this attribute so we can take a look?

Arthur, thank you for responding and great timing because I just figure it out. Someone else had checked in a new entity and it was like this:

Table("")]
public class Program

What took all the time was tracking down what entity and it was just bad timing that I modified some other entities and thought I broke something so I was looking in the wrong places. I finally checked the previous users checkin and it led me to the offending class.

Would it be possible for the message to tell us what entity/class is throwing this error so we can track it down more quickly should it happen again?

Thank you.

@wjvii I'll think about if its feasible to improve the message here. It may not be since it is happening outside the scope of EF. Can you still post the full stack trace?

@ajcvickers That would be great. Happy to provide a full stack trace if you can tell me how to get what you want. I copied the message with some trace information in it from the Test Explorer window originally so I just need to know how to get the extra detail you want and I will be happy to get it for you.

@wjvii My mistake! You did post the stack trace already. (I've been through a lot of different issues today and got confused!) We will discuss and get back to you.

@ajcvickers Absolutely no worries, I definitely understand! Thank you and the team for seeing what the options are and hope you figure a good way to include more information! I will keep an eye on this issue for updates.

Notes from team discussion: based on where the message is coming from (the annotation constructor) and the data available at that point, it isn't really feasible to add additional information to the message here.

Well bummer but understand, it is what it is. At least maybe this thread will be useful to someone that finds it if they have the same error and will know to look at any/all entities for the invalid attribute.

I've just encountered a similar error when scaffolding an sqlite database.

System.ArgumentException: The string argument 'name' cannot be empty.
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasIndex(String[] propertyNames, String name)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitUniqueConstraint(EntityTypeBuilder builder, DatabaseUniqueConstraint uniqueConstraint)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitUniqueConstraints(EntityTypeBuilder builder, ICollection`1 uniqueConstraints)
   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.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluarlize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.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)
The string argument 'name' cannot be empty.

I believe it's due to scaffolding a database that contains an index that references a column name with a reserved word (ie. "Order")

@archanox This issue is closed - Suggest you file a new issue with proper replocation steps.

Was this page helpful?
0 / 5 - 0 ratings