配置系统初始化失败
Configuration system failed to initialize
我正在尝试从包管理器控制台为 Visual Studio 2013 年的项目启用代码优先迁移。 (上下文:我正在尝试从本教程中了解 Web 部署 (https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/preparing-databases))
我输入:
PM>启用迁移
并得到以下内容:
> Checking if the context targets an existing database...
> System.TypeInitializationException: The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception. ---> System.TypeInitializationException: The type
> initializer for 'System.Data.Entity.Internal.AppConfig' threw an
> exception. ---> System.Configuration.ConfigurationErrorsException:
> Configuration system failed to initialize --->
> System.Configuration.ConfigurationErrorsException: Unrecognized
> configuration section compilation. The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception.
我尝试了其他 Stack Overflow 帖子(以及 ASP.NET 论坛)的建议,但没有任何效果。其他帖子表明 Web.config 文件可能有问题,但我所做的任何更改都没有修复错误。
这是我的 Web.config 文件的开头:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
我将此代码段添加到我的 Web.config 文件中,但将其放在了错误的位置:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
它应该是 system.web 的子项,而不是介于位置和运行时之间。
我正在尝试从包管理器控制台为 Visual Studio 2013 年的项目启用代码优先迁移。 (上下文:我正在尝试从本教程中了解 Web 部署 (https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/preparing-databases))
我输入:
PM>启用迁移
并得到以下内容:
> Checking if the context targets an existing database...
> System.TypeInitializationException: The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception. ---> System.TypeInitializationException: The type
> initializer for 'System.Data.Entity.Internal.AppConfig' threw an
> exception. ---> System.Configuration.ConfigurationErrorsException:
> Configuration system failed to initialize --->
> System.Configuration.ConfigurationErrorsException: Unrecognized
> configuration section compilation. The type initializer for
> 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an
> exception.
我尝试了其他 Stack Overflow 帖子(以及 ASP.NET 论坛)的建议,但没有任何效果。其他帖子表明 Web.config 文件可能有问题,但我所做的任何更改都没有修复错误。
这是我的 Web.config 文件的开头:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
我将此代码段添加到我的 Web.config 文件中,但将其放在了错误的位置:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
它应该是 system.web 的子项,而不是介于位置和运行时之间。