ASP.NET Core 3.0 Error 'Unable to cast object of type' while Scaffolding Existing Database

asp.net-core-3.0 c# entity-framework-core entity-framework-core-3.0 sql

Question

I am using Visual Studio 2019. My application is in ASP.NET Core 3.0.

I'm trying to scaffold an existing database from LocalDb using the Package Manager Console with this command:

 Scaffold-DbContext "Server=(localdb)\mssqllocaldb;
 Database=hamdoonsoft;Trusted_Connection=True;" 
 Microsoft.EntityFrameworkCore.SqlServer -OutputDir Appcontext

After a while I'm getting this error:

Unable to cast object of type 'Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggingDefinitions' to type 'Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal.SqlServerLoggingDefinitions'.

What's causing it and how can I resolve it?

1
1
6/11/2019 5:12:06 AM

Popular Answer

This is a known issue in EFCore Preview 4, which was targeted to be fixed in Preview 5. Having encountered this issue myself, I can confirm that updating to Preview 5, which leaves my .csproj references for EFCore looking like this:

<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview5.19227.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview5.19227.1" />

Has resolved the issue and allowed me to scaffold a DBContext.

2
6/10/2019 4:30:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow