C# 必需属性";“类型”;在EF迁移期间未找到
对Azure SQL数据库运行EF迁移时引发以下错误:C# 必需属性";“类型”;在EF迁移期间未找到,c#,entity-framework,ef-code-first,azure-sql-database,entity-framework-migrations,C#,Entity Framework,Ef Code First,Azure Sql Database,Entity Framework Migrations,对Azure SQL数据库运行EF迁移时引发以下错误: System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnecti
System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Required attribute 'type' not found. (--DATA OMITTED FOR PRIVACY REASONS--)
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings()
at System.Diagnostics.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Diagnostics.TraceSwitch.get_Level()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnectionFactory..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlClientFactory.CreateConnection()
at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(String providerInvariantName)
at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
at System.Data.Entity.Internal.LazyInternalContext.get_Connection()
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
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.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
System.TypeInitializationException:“System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常。-->System.TypeInitializationException:“System.Data.SqlClient.SqlConnectionFactory”的类型初始值设定项引发异常。-->System.TypeInitializationException:“System.Data.SqlClient.SqlPerformanceCounters”的类型初始值设定项引发异常。-->System.Configuration.ConfigurationErrorsException:未找到必需的属性“type”。(-出于隐私原因省略数据--)
在System.Configuration.BaseConfigurationRecord.EvaluateOne(字符串[]键、SectionInput输入、布尔isTrusted、FactoryRecord FactoryRecord、SectionRecord SectionRecord、Object parentResult)
在System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord FactoryRecord、SectionRecord SectionRecord、Object parentResult、Boolean getLkg、Boolean getRuntimeObject、Object&result、Object&resultRuntimeObject)
位于System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey、布尔getLkg、布尔checkPermission、布尔getRuntimeObject、布尔RequestISHER、对象与结果、对象与结果EntimeObject)
位于System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey、布尔getLkg、布尔checkPermission、布尔getRuntimeObject、布尔RequestISHER、对象与结果、对象与结果EntimeObject)
位于System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey、布尔getLkg、布尔checkPermission、布尔getRuntimeObject、布尔RequestISHER、对象与结果、对象与结果EntimeObject)
位于System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey)
位于System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(字符串sectionName)
位于System.Configuration.ConfigurationManager.GetSection(字符串sectionName)
位于System.Configuration.PrivilegedConfiguration Manager.GetSection(String sectionName)
在System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()中
在System.Diagnostics.DiagnosticsConfiguration.Initialize()中
在System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings()中
在System.Diagnostics.Switch.InitializeConfigSettings()中
在System.Diagnostics.Switch.InitializeWithStatus()中
在System.Diagnostics.Switch.get_SwitchSetting()中
在System.Diagnostics.TraceSwitch.get_Level()中
位于System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName,String categoryHelp)
位于System.Data.SqlClient.SqlPerformanceCounters..ctor()处
位于System.Data.SqlClient.SqlPerformanceCounters..cctor()处
---内部异常堆栈跟踪的结束---
位于System.Data.SqlClient.SqlConnectionFactory..cctor()处
---内部异常堆栈跟踪的结束---
在System.Data.SqlClient.SqlConnection..cctor()处
---内部异常堆栈跟踪的结束---
在System.Data.SqlClient.SqlConnection..ctor()处
位于System.Data.SqlClient.SqlClientFactory.CreateConnection()处
位于System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(字符串providerInvariantName)
位于System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionString设置(ConnectionString设置appConfigConnection)
在System.Data.Entity.Internal.LazyInternalConnection.Initialize()中
在System.Data.Entity.Internal.LazyInternalConnection.get_Connection()中
在System.Data.Entity.Internal.LazyInternalContext.get_Connection()中
位于System.Data.Entity.Infrastructure.DbContextInfo..ctor(类型contextType、DbProviderInfo modelProviderInfo、AppConfig config、DbConnectionInfo connectionInfo)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置,DbContext用户上下文)
位于System.Data.Entity.Migrations.DbMigrator..ctor(dbmigrations配置)
位于System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration MigrationConfiguration)
位于System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()处
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处
位于System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner)
位于System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName、String语言、String rootNamespace、Boolean ignoreChanges)
位于System.Data.Entity.Migrations.AddMigrationCommand.Execute(字符串名称、布尔值强制、布尔值忽略更改)
在System.Data.Entity.Migrations.AddMigrationCommand.c__DisplayClass2.b__0()中
位于System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(操作命令)
“System.Data.SqlClient.SqlConnection”的类型初始值设定项引发异常。
在我为应用程序启用跟踪后,错误开始出现。虽然我已经解决了这个问题,但我还是以问答的形式发布在这里,以防其他人遇到这个问题。这个问题是由我们的跟踪事件监听器引起的。运行迁移时,只需注释掉web.config/app.config文件中的
Systems.Diagnostics
标记
如果这个答案对您有帮助,请+1。在我的情况下,问题来自
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
当我删除type=“声明时,因为VS 2013 U4声明“不允许使用'type'属性”。当将配置声明的删除反向到上面时,它再次开始工作
无论您使用的是哪种诊断版本。(至少在2.5.0.0之前)