问题描述
我和EF5在MVC 4 ASPNET网站工作。
在当地,一切都运行得很好,但是当我将它发布到IIS,并尝试进入,我得到的错误
对于'System.Data.Entity.Internal.AppConfig'的类型初始值引发了异常。
详细的异常
发生错误创建的EntityFramework配置节处理程序:对的DbContext类型GdpSoftware.Server.Data.GdpSoftwareDbContext,GdpSoftware.Server.Data应用程序配置中指定了多个配置。每个上下文一次只能配置。 (E:\\ APP \\ web.config行104)
我检查previous问题在计算器,我已经卸载并通过的NuGet的EntityFramework重新安装,并检查每个引用它在每一个项目都是EF5。我还检查了每个项目选择的框架是4.5。
任何想法,可能是什么导致了问题?
谢谢!吉列尔莫。
的web.config
<?XML版本=1.0编码=UTF-8&GT?;
<! -
有关如何配置ASP.NET应用程序的更多信息,请访问:
http://go.microsoft.com/fwlink/?LinkId=169433
- >
<结构>
< configSections>
<节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本5.0.0.0 =文化=中性公钥= b77a5c561934e089requirePermission =FALSE/> <! - 有关Entity Framework的配置的详细信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >< / configSections>
<&是connectionStrings GT;
<添加名称=GdpSoftwareConnectionString的connectionString =持续安全信息= FALSE;用户ID =用户;密码=密码;初始目录=数据库名;数据源=服务器的providerName =System.Data.SqlClient的/>
<添加名称=GdpSoftware.Server.Data.GdpSoftwareDbContext的connectionString =GdpSoftware.Server.Data.GdpSoftwareDbContext_ConnectionString的providerName =System.Data.SqlClient的/>
<添加名称=GdpSoftware.Server.Ui.Web.Models.UsersContext的connectionString =GdpSoftware.Server.Ui.Web.Models.UsersContext_ConnectionString的providerName =System.Data.SqlClient的/>
< /&是connectionStrings GT;
<&的appSettings GT;
<添加键=网页:版本值=2.0.0.0/>
<添加键=网页:启用VALUE =FALSE/>
<添加关键=preserveLoginUrlVALUE =真/>
<添加键=ClientValidationEnabledVALUE =真/>
<添加键=UnobtrusiveJavaScriptEnabledVALUE =真/>
< /的appSettings>
<&的System.Web GT;
<编译调试=真targetFramework =4.5/>
<的httpRuntime targetFramework =4.5/>
<身份验证模式=表格>
<形式loginUrl =〜/帐号/登录超时=2880/>
< /认证>
<网页和GT;
<&命名空间GT;
<添加命名空间=System.Web.Helpers/>
<添加命名空间=System.Web.Mvc/>
<添加命名空间=System.Web.Mvc.Ajax/>
<添加命名空间=System.Web.Mvc.Html/>
<添加命名空间=System.Web.Optimization/>
<添加命名空间=System.Web.Routing/>
<添加命名空间=System.Web.WebPages/>
< /命名空间>
< /页>
<! - BEGIN - 看错误的部署 - >
<的customErrors模式=关/>
<! - 完 - 看错误的部署 - >
< /system.web>
< system.webServer>
<! - BEGIN - 看错误的部署 - >
< httpErrors errorMode =详细/>
< ASP scriptErrorSentToBrowser =真/>
<! - 完 - 看错误的部署 - >
<验证validateIntegratedModeConfiguration =FALSE/>
<&处理GT;
<清除NAME =ExtensionlessUrlHandler-ISAPI-4.0_32bit/>
<清除NAME =ExtensionlessUrlHandler-ISAPI-4.0_64bit/>
<清除NAME =ExtensionlessUrlHandler - 集成 - 4.0/>
<添加名称=ExtensionlessUrlHandler-ISAPI-4.0_32bitPATH =*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS模块=IsapiModulescriptProcessor =%WINDIR%\\ Microsoft.NET \\框架\\ v4.0.30319 \\ ASPNET_ISAPI.DLLpreCondition = classicMode,runtimeVersionv4.0,bitness32responseBufferLimit =0/>
<添加名称=ExtensionlessUrlHandler-ISAPI-4.0_64bitPATH =*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS模块=IsapiModulescriptProcessor =%WINDIR%\\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ ASPNET_ISAPI.DLLpreCondition = classicMode,runtimeVersionv4.0,bitness64responseBufferLimit =0/>
<添加名称=ExtensionlessUrlHandler - 集成 - 4.0PATH =*。动词=GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONSTYPE =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< /处理器>
< staticContent>
< mimeMap fileExtension =小胡子。mime类型=text / plain的/>
< / staticContent>
<安全>
<&的requestFiltering GT;
< fileExtensions>
<添加fileExtension =允许=真/&GT胡子。
< / fileExtensions>
< /&的requestFiltering GT;
< /安全>
< /system.webServer>
<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Helpers公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-2.0.0.0NEWVERSION =2.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.Mvc公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-4.0.0.0NEWVERSION =4.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=System.Web.WebPages公钥=31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-2.0.0.0NEWVERSION =2.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Castle.Windsor公钥=407dd0808d44fbdc文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-3.2.0.0NEWVERSION =3.2.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Newtonsoft.Json公钥=30ad4fe6b2a6aeed文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-4.5.0.0NEWVERSION =4.5.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Microsoft.Owin.Host.SystemWeb公钥=31bf3856ad364e35文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-1.0.0.0NEWVERSION =1.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=Castle.Core公钥=407dd0808d44fbdc文化=中性/>
< bindingRedirect oldVersion =0.0.0.0-3.2.0.0NEWVERSION =3.2.0.0/>
< / dependentAssembly>
< / assemblyBinding>
< /运行>
<&的EntityFramework GT;
< defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework/>
<&上下文GT;
<上下文类型=GdpSoftware.Server.Data.GdpSoftwareDbContext,GdpSoftware.Server.DatadisableDatabaseInitialization =真>
< databaseInitializer type=\"System.Data.Entity.MigrateDatabaseToLatestVersion`2[[GdpSoftware.Server.Data.GdpSoftwareDbContext, GdpSoftware.Server.Data],[GdpSoftware.Server.Data.Migrations.Configuration,GdpSoftware.Server.Data],的EntityFramework/>
< /背景>
< /背景>
< /&的EntityFramework GT;
< /结构>
我需要通过defaultConnectionFactory改变是SqlConnectionFactory而不是默认的
<&的EntityFramework GT;
< defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework>
<&参数GT;
<参数值=<我的连接字符串>中/>
< /参数>
< / defaultConnectionFactory>
< /&的EntityFramework GT;
http://blogs.msdn.com/b/davidobando/archive/2012/08/14/changing-ef-s-default-provider-from-localdb-to-sql-server.aspx
I'm working with EF5 in a MVC 4 aspnet website.Locally, everything works just fine, but when I publish it to the IIS and try to enter, I get the error"The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception."
Detailed exceptionAn error occurred creating the configuration section handler for entityFramework: Configuration for DbContext type 'GdpSoftware.Server.Data.GdpSoftwareDbContext, GdpSoftware.Server.Data' is specified multiple times in the application configuration. Each context can only be configured once. (E:\App\web.config line 104)
I checked previous question in StackOverflow, and I already uninstalled and reinstalled through Nuget EntityFramework and checked that each reference to it in each project is EF5. I also checked that the selected framework in each project is 4.5.
Any idea, What might be causing the issue?Thanks! Guillermo.
web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add name="GdpSoftwareConnectionString" connectionString="Persist Security Info=False;User ID=user;Password=password;Initial Catalog=databasename;Data Source=server" providerName="System.Data.SqlClient" />
<add name="GdpSoftware.Server.Data.GdpSoftwareDbContext" connectionString="GdpSoftware.Server.Data.GdpSoftwareDbContext_ConnectionString" providerName="System.Data.SqlClient"/>
<add name="GdpSoftware.Server.Ui.Web.Models.UsersContext" connectionString="GdpSoftware.Server.Ui.Web.Models.UsersContext_ConnectionString" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<!-- BEGIN - TO SEE THE ERRORS ON THE DEPLOYMENT-->
<customErrors mode="Off" />
<!-- END - TO SEE THE ERRORS ON THE DEPLOYMENT-->
</system.web>
<system.webServer>
<!-- BEGIN - TO SEE THE ERRORS ON THE DEPLOYMENT-->
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true" />
<!-- END - TO SEE THE ERRORS ON THE DEPLOYMENT-->
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<staticContent>
<mimeMap fileExtension=".mustache" mimeType="text/plain" />
</staticContent>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".mustache" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.Windsor" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<contexts>
<context type="GdpSoftware.Server.Data.GdpSoftwareDbContext, GdpSoftware.Server.Data" disableDatabaseInitialization="true">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[GdpSoftware.Server.Data.GdpSoftwareDbContext, GdpSoftware.Server.Data], [GdpSoftware.Server.Data.Migrations.Configuration, GdpSoftware.Server.Data]], EntityFramework" />
</context>
</contexts>
</entityFramework>
</configuration>
I needed to change by defaultConnectionFactory to be SqlConnectionFactory instead of the default
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="<My Connection String>" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
这篇关于对于“System.Data.Entity.Internal.AppConfig'的类型初始值引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!