efcore: Scaffold-DbContext PMC Command doesn't work (Bug)

Reverse engineer doesn’t work and displays an error message on the console.

PMC Command:

Scaffold-DbContext "Server=YUANT;Database=NetAntiError;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

If you are seeing an exception, include the full exceptions details (message and stack trace).

System.InvalidCastException: Unable to cast object of type 'Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggingDefinitions' to type 'Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal.SqlServerLoggingDefinitions'.
   at Microsoft.EntityFrameworkCore.SqlServer.Internal.SqlServerResources.LogFoundDefaultSchema(IDiagnosticsLogger logger)
   at Microsoft.EntityFrameworkCore.SqlServer.Internal.SqlServerLoggerExtensions.DefaultSchemaFound(IDiagnosticsLogger`1 diagnostics, String schemaName)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.GetDefaultSchema(DbConnection connection)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions options, String rootNamespace, String modelNamespace, String contextNamespace, String language, String contextDir, String contextName, 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, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, 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)
Unable to cast object of type 'Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggingDefinitions' to type 'Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal.SqlServerLoggingDefinitions'.

Steps to reproduce

  • Create a new ASP NET Core project.
  • Add Microsoft.EntityFrameworkCore.SqlServer
  • Add Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
  • Add Microsoft.EntityFrameworkCore.Tools
  • Add connection string on appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection": "Server=YUANT;Database=NetAntiError;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

In the previous version, a procedure like this still works. Am I missing something?

Further technical details

EF Core version: 3.0.0-preview4.19216.3 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Ms. Windows 10 IDE: Visual Studio 2019 16.0.2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Found the issue: I mistakenly thought the latest update of visual studio that hit with the preview5 announcment had the preview5 .net core sdk with it. @guidevnet 's comment triggered the thought of downloading the sdk again and installing it and wham, it all works. Thanks for the triggering suggestion, and thanks to all who helped.

@PeaStew Yeah, me too using blazor! (server-side). Ha, this is Microsoft’s fault: if the new products where less awesome, we wouldn’t bother using EF6 and MVC.

100%… I’m back to being a full-stack developer again, I was pushing all the Javascript off to team members because I hate it so much 😉

I’m in the same position, pushed Blazor onto my team for a software release in late October but little issues like this make it difficult, using nightlies makes early UAT complicated when you don’t know what will break when, only that something will break 😃