Add-Migration NullReferenceException
See original GitHub issueThe database context generated by Scaffold-DbContext
. After generating the context I moved all entity configurations in OnModelCreating
to separate config file implementing IEntityTypeConfiguration<T>
. OnModelCreating
is like this now.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
}
The same setup is working in EF Core v2.2.6.
Steps to reproduce
Add-Migration IntitialSchema
StackTrace
DesignTimeDbContextFactoryBase.BasePath: D:\Working_Projects
DesignTimeDbContextFactoryBase.Create(string): Connection string: 'Server=DW;Database=DeveDB;Trusted_Connection=True;Application Name=Portal;'.
DbContext Assembly: Portal.Persistence, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.Literal(String value)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(CreateTableOperation operation, IndentedStringBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>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)
Object reference not set to an instance of an object.
Further technical details
EF Core version: 3.0.0-rc1.19456.14 Database provider: Microsoft.EntityFrameworkCore.SqlServer (3.0.0-rc1.19456.14) Target framework: .NET Core 3.0 SDK: .NET Core 3.0rc1 Operating system: Windows 10 IDE: Visual Studio 2019 16.2.5
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Object reference not set to an instance of an object
We use to get the following error when we try to run add-migration. We use Entity Framework Core 2.1. System.NullReferenceException: Object ...
Read more >Object reference not set to an instance of an object.
and run dotnet ef migrations it'll work fine. The problem is with the current main branch while mapping the passenger entity.
Read more >FIX: Object reference not set to an instance of object Add- ...
Quick fix for System.NullReferenceException: Object reference not set to an instance of an object · Open Solution Explorer in Visual Studio & go ......
Read more >Add-Migration NullReferenceException #6389
Hi, I try to add migration to EF and get null pointer exception How can I debug the process? PM> Add-Migration "Added_xxx" -Context ......
Read more >Why "System.NullReferenceException " is occurred in ...
It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it’s related to #17474.
Steps to reproduce.
Create a database
Scaffold DbContext
Create the following models
DbContext
and entity configurationsNow run
Stacktrace
If we remove
.HasComment("Author fullname")
migration will add successfully.@404Prachi You need to update to ASP.NET Core 3.1 and EF Core 3.1.