【发布时间】:2014-11-18 10:03:03
【问题描述】:
我正在尝试使用 Web 部署将 MVC 应用程序部署到 EC2 实例,并且在我尝试运行该应用程序之前一切正常。我收到以下错误:
解析器错误消息:为 entityFramework 创建配置节处理程序时出错:在应用程序配置中多次指定 DbContext 类型“Project.Modules.AppDbContext, Project”的配置。每个上下文只能配置一次。
我查看了所有我能找到的相关问题(error There is a duplicate 'entityFramework' section defined、There is a duplicate 'entityFramework' section defined - EntityFramework6 upgrade、The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception、The provider for invariant name System.Data.SqlClient is specified multiple times)。它是一个 MVC 应用程序,因此有多个 Web.config 文件,但它抱怨的 EF 部分在这两个地方都不存在。以下是我的配置文件的相关部分:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
--------more config settings here---------
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=MYIP;Initial Catalog=db;Persist Security Info=True;User ID=user;Password=password" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
我听说它应该在 6.1.0 中解决许多其他问题。如果我从 configSection 中删除该条目,它会给我另一个关于它如何找不到正确资源的错误。可能值得注意的另一件事是,如果我部署并取消选中“执行代码优先迁移”,它只会超时,而不是给我上述错误。
【问题讨论】:
标签: c# asp.net-mvc entity-framework web-config asp.net-mvc-5