The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

前端 未结 26 870
臣服心动
臣服心动 2020-11-30 06:17

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

相关标签:
26条回答
  • 2020-11-30 06:58

    in my case

    <section name="entityFramework"
    

    must be updated from version 4 to 6. I mean a project was updated EntityFramework from 4 to 6 but web.config was not updated.

    0 讨论(0)
  • 2020-11-30 06:58

    If you are maintaining one more cinfiguration file for app.config , Don't include any key in parent page.

    Parent Page : app.config

    <appSettings configSource="appSettings.config">
        <add key="ClientSettings" value="venice" /> <!-- Don't add Key Here -->
    </appSettings>
    

    Child Page : appSettings.config

    <appSettings>
      <add key="ClientSettings" value="venice"/> <!-- add Here -->
    </appSettings>
    
    0 讨论(0)
  • 2020-11-30 06:58

    I had same problem. After one day, I got it.

    Problem was from adding two smtp tags in mailSettings under <system.net>.

    0 讨论(0)
  • 2020-11-30 06:59

    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>
    

    http://blogs.msdn.com/b/davidobando/archive/2012/08/14/changing-ef-s-default-provider-from-localdb-to-sql-server.aspx

    0 讨论(0)
  • 2020-11-30 07:01

    Do the following in the App.config file,

    1. Put the connectionStrings element is after the configSections element.
    2. Put the startup element after the connectionStrings element.
    <?xml version="1.0" encoding="utf-8"?>
     <configuration>
       <configSections>
             <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
       </configSections>
       <connectionStrings>
             <add name="SchedulingContext" connectionString="Data Source=XXX\SQL2008R2DEV;Initial Catalog=YYY;Persist Security Info=True;User ID=sa;Password=XXX"   providerName="System.Data.SqlClient"/>
       </connectionStrings>
       <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>       
     </configuration>
    
    0 讨论(0)
  • 2020-11-30 07:01

    If you use ASP.NET and IISExpress go to "C:\Users\\Documents\IISExpress\config\applicationhost.config", search for your Project and look if you have a faulty virtualDirectory entry.

    0 讨论(0)
提交回复
热议问题