npgsql/EntityFramework6.Npgsql

Throw System.Data.Entity.Core.ProviderIncompatibleException when "Enable migrations"

billzhuang opened this issue · 4 comments

sample repo here: https://github.com/myspyx/ef6play

pretty simple code from
https://www.npgsql.org/ef6/index.html
and https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/new-database

the code works well at first time, create databse automaticly for me, but if I change anything in the model, and try to "Enable migrations", it will throw exception of System.Data.Entity.Core.ProviderIncompatibleException.

Any idea? I try different Postgres verision, no lucky.
Run Postgres in docker for test with below
docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres:11

IDE: Rider 2021.2.2

21:27:09.607 |I| EntityFrameworkRunnerProgram  | :1                 | Using EntityFramework 6.4.0
21:27:12.475 |E| ScaffoldInitialMigrationRunner| :1                 | Inner exception stack trace: System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.TypeInitializationException: The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.Assembly.GetTypes() at Npgsql.TypeMapping.GlobalTypeMapper.SetupGlobalTypeMapper() at Npgsql.TypeMapping.GlobalTypeMapper..cctor() --- End of inner exception stack trace --- at Npgsql.TypeMapping.GlobalTypeMapper.get_Instance() at Npgsql.TypeMapping.ConnectorTypeMapper..ctor(NpgsqlConnector connector) at Npgsql.NpgsqlConnector.<LoadDatabaseInfo>d__149.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnector.<Open>d__148.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Npgsql.NpgsqlConnection.Open() at Npgsql.NpgsqlServices.UsingPostgresDbConnection(NpgsqlConnection connection, Action`1 action) at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection) at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) --- End of inner exception stack trace --- at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) --- End of inner exception stack trace --- at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized() at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()

--- EXCEPTION #1/1 [LoggerException]
Message = “
  Inner exception stack trace: System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure. ---> System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.TypeInitializationException: The type initializer for 'Npgsql.TypeMapping.GlobalTypeMapper' threw an exception. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
     at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
     at System.Reflection.Assembly.GetTypes()
     at Npgsql.TypeMapping.GlobalTypeMapper.SetupGlobalTypeMapper()
     at Npgsql.TypeMapping.GlobalTypeMapper..cctor()
     --- End of inner exception stack trace ---
     at Npgsql.TypeMapping.GlobalTypeMapper.get_Instance()
     at Npgsql.TypeMapping.ConnectorTypeMapper..ctor(NpgsqlConnector connector)
     at Npgsql.NpgsqlConnector.<LoadDatabaseInfo>d__149.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnector.<Open>d__148.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Npgsql.NpgsqlConnection.Open()
     at Npgsql.NpgsqlServices.UsingPostgresDbConnection(NpgsqlConnection connection, Action`1 action)
     at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection)
     at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
     --- End of inner exception stack trace ---
     at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
     at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
     --- End of inner exception stack trace ---
     at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
     at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
     at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
     at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
     at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
     at System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
     at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
     at System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action`1 writeXml)
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
     at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
     at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
     at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
     at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogMessage(ILogger this, LoggingLevel level, String message)
     at JetBrains.EntityFramework.Runner620.CommandRunnerBase`2.JetBrains.EntityFramework.Runner620.ICommandRunner<TIn>.Run(TIn command)
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at JetBrains.EntityFramework.Runner620.EntityFrameworkRunnerProgram.Main(String[] args)
”

21:27:12.564 |E| EntityFrameworkRunnerProgram  | :1                 | An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.

--- EXCEPTION #1/3 [ToolingException]
Message = “An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.”
ExceptionPath = Root.InnerException.InnerException
ClassName = System.Data.Entity.Migrations.Design.ToolingException
HResult = COR_E_EXCEPTION=80131500
Source = EntityFramework
SafeSerializationManager.m_serializedStates.#0 = System.Data.Entity.Migrations.Design.ToolingException+ToolingExceptionState
CLR_SafeSerializationManager_RealType.Data = System.Data.Entity.Migrations.Design.ToolingException
CLR_SafeSerializationManager_RealType.UnityType = 4
CLR_SafeSerializationManager_RealType.AssemblyName = “EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
StackTraceString = “
  at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
     at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language, String rootNamespace)
     at JetBrains.EntityFramework.Runner620.ScaffoldInitialMigrationRunner.DoRun(EnableMigrationsCommand command)
     at JetBrains.EntityFramework.Runner620.CommandRunnerBase`2.JetBrains.EntityFramework.Runner620.ICommandRunner<TIn>.Run(TIn command)
”

--- Outer ---

--- EXCEPTION #2/3 [TargetInvocationException]
Message = “Exception has been thrown by the target of an invocation.”
ExceptionPath = Root.InnerException
ClassName = System.Reflection.TargetInvocationException
InnerException = “Exception #1 at Root.InnerException.InnerException”
HResult = COR_E_TARGETINVOCATION=80131604
Source = mscorlib
StackTraceString = “
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at JetBrains.EntityFramework.Runner620.EntityFrameworkRunnerProgram.Main(String[] args)
”

--- Outer ---

--- EXCEPTION #3/3 [LoggerException]
Message = “Exception has been thrown by the target of an invocation.”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #2 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogException(ILogger this, LoggingLevel level, Exception exception, ExceptionOrigin exceptionOrigin, String comment)
     at JetBrains.EntityFramework.Runner620.EntityFrameworkRunnerProgram.<>c.<InstallExceptionHandler>b__4_0(Object sender, UnhandledExceptionEventArgs eventArgs)
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at JetBrains.EntityFramework.Runner620.EntityFrameworkRunnerProgram.Main(String[] args)
”




Operation FAILED
roji commented

@billzhuang note that this provider is archived and no longer being actively maintained.

@roji yep, since EF6 also live in maintain Mode, I suppose this repo should work with EF6 together happy.:)

Any idea from your experience why this exception happened in enable migration phase?

Appreciated.

add assembly binding in app.config
<dependentAssembly> <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> </dependentAssembly>
There is an assembly version conflict.

Hi @icewindq , amazing! You saved my time. After add the binding redirect, works like a charm.