C# 如何使用托管标识从Visual Studio运行EF6代码优先迁移

C# 如何使用托管标识从Visual Studio运行EF6代码优先迁移,c#,azure,entity-framework-6,azure-sql-database,azure-managed-identity,C#,Azure,Entity Framework 6,Azure Sql Database,Azure Managed Identity,我创建了一个系统管理的标识,并通过Azure服务身份验证在Azure和Visual Studio 2019内进行调试,但是,当我从Package Manager控制台运行更新数据库时,我无法应用代码优先迁移,以下情况除外 正如我所说,除了迁移,它在任何地方都可以工作,这让我觉得Powershell无法定位dll。我尝试从项目的build文件夹运行该命令,但引发了相同的异常 EntityFramework 6.2 Microsoft.Azure.Services.AppAuthenticatio

我创建了一个系统管理的标识,并通过Azure服务身份验证在Azure和Visual Studio 2019内进行调试,但是,当我从Package Manager控制台运行
更新数据库时,我无法应用代码优先迁移,以下情况除外

正如我所说,除了迁移,它在任何地方都可以工作,这让我觉得Powershell无法定位dll。我尝试从项目的build文件夹运行该命令,但引发了相同的异常

  • EntityFramework 6.2
  • Microsoft.Azure.Services.AppAuthentication 1.5.0
是否需要进行其他配置

System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception. ---> System.ArgumentException: Failed to instantiate an authentication provider with type 'Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider, Microsoft.Azure.Services.AppAuthentication' for 'ActiveDirectoryInteractive'. ---> System.TypeLoadException: Could not load type 'Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider' from assembly 'Microsoft.Azure.Services.AppAuthentication'.
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
       at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
       at System.Type.GetType(String typeName, Boolean throwOnError)
       at System.Data.SqlClient.SqlAuthenticationProviderManager..ctor(SqlAuthenticationProviderConfigurationSection configSection)
       --- End of inner exception stack trace ---
       at System.Data.SqlClient.SqlAuthenticationProviderManager..ctor(SqlAuthenticationProviderConfigurationSection configSection)
       at System.Data.SqlClient.SqlAuthenticationProviderManager..cctor()
       --- End of inner exception stack trace ---
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
       at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
       at System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
       at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
       at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute(Action operation)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
       at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
    The type initializer for 'System.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.
    ```
System.TypeInitializationException:“System.Data.SqlClient.SqlAuthenticationProviderManager”的类型初始值设定项引发异常。-->System.ArgumentException:未能为“ActiveDirectoryInteractive”实例化类型为“Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider,Microsoft.Azure.Services.AppAuthentication”的身份验证提供程序。-->System.TypeLoadException:无法从程序集“Microsoft.Azure.Services.AppAuthentication”加载类型“Microsoft.Azure.Services.AppAuthentication.SqlAppAuthenticationProvider”。
位于System.RuntimeTypeHandle.GetTypeByName(字符串名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、StackScrawMarkHandle stackMark、IntPtr pPrivHostBinder、布尔loadTypeFromPartialName、ObjectHandleOnStack类型)
在System.RuntimeTypeHandle.GetTypeByName(字符串名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、StackScrawlMark和stackMark、IntPtr pPrivHostBinder、布尔loadTypeFromPartialName)
在System.RuntimeType.GetType(字符串类型名称、布尔throwOnError、布尔ignoreCase、布尔reflectionOnly、堆栈爬网标记和堆栈标记)
在System.Type.GetType(字符串typeName,布尔throwOnError)
位于System.Data.SqlClient.SqlAuthenticationProviderManager..ctor(SqlAuthenticationProviderConfigurationSection configSection)
---内部异常堆栈跟踪的结束---
位于System.Data.SqlClient.SqlAuthenticationProviderManager..ctor(SqlAuthenticationProviderConfigurationSection configSection)
位于System.Data.SqlClient.SqlAuthenticationProviderManager..cctor()处
---内部异常堆栈跟踪的结束---
位于System.Data.SqlClient.SqlInternalConnectionDS..ctor(DbConnectionPoolIdentity、SqlConnectionString connectionOptions、SqlCredential凭证、对象提供信息、String newPassword、SecureString newSecurePassword、Boolean redirectedUserInstance、SqlConnectionString userConnectionOptions、SessionData重新连接SessionData、DbConnectionPool池、String accessToken、Boolean applyTransientFAulthandle,SqlAuthenticationProviderManager(sqlAuthProviderManager)
位于System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions、DbConnectionPoolKey、Object poolGroupProviderInfo、DbConnectionPool、DBConnectionOwningConnection、DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池、DbConnectionOwningObject、DbConnectionOptions选项、DbConnectionPoolKey池键、DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection-owningObject、DbConnectionOptions-userOptions、DbConnectionInternal-oldConnection)
位于System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject、DbConnectionOptions userOptions、DbConnectionInternal oldConnection)
位于System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject、UInt32 waitForMultipleObjectsTimeout、Boolean allowCreate、Boolean OnlyOnEckConnection、DbConnectionOptions userOptions、DbConnectionInternal和connection)
位于System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject、TaskCompletionSource`1重试、DbConnectionOptions用户选项、DbConnectionInternal和connection)
位于System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection、TaskCompletionSource`1重试、DbConnectionOptions用户选项、DbConnectionInternal oldConnection、DbConnectionInternal&connection)
位于System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection、DbConnectionFactory connectionFactory、TaskCompletionSource`1重试,DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection、DbConnectionFactory connectionFactory、TaskCompletionSource`1重试、DbConnectionOptions用户选项)
位于System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1重试)
位于System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1重试)
在System.Data.SqlClient.SqlConnection.Open()处
在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b_u36(DbConnection t,DbConnectionInterceptionContext c)
在System.Data.Entity.Infrastructure.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget,Action`2 operation,TInterceptionContext interceptionContext,Action`3 executing,Action`3 executed)
位于System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext interceptionContext)
位于System.Data.Entity.SqlServer.SqlProviderServices.c__DisplayClass33.b__u32()
在System.Data.Entity.Infrastructure.DbExecutionStrategy.c_uuDisplayClass1.b_uuu0()中
在System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1操作)中
位于System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute(操作操作)
位于System.Data.Entity.SqlServer.SqlProvid