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

前端 未结 26 871
臣服心动
臣服心动 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:52

    This weird error happens, when you play around with different versions of EntityFramework versions in Nuget Packages like I did.

    First, Uninstall your Entity Framework DLL from NuGet packages and then Clean up app.config. By removing the entry from configSections and entity framework element.

    Next, install the desired version. This should fix the problem.

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

    I have broken my head over this issue, and finally here's what worked for me:-

    Step1 : Uninstall Entity framework using Nuget package manager

    Step2: Delete Entityframework element from App.config

    Step3: Reinstall desired version of Entity Framework.

    Step4: delete Migrations table and Migrations folder.

    Step5: Enable Migrations and Add Migration and Update database

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

    I solved this problem removing DbproviderFactory in the section system.data of the file machine.config, there was some dirty data when I installed fbclient.dll.

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

      <system.data>
        <!-- <DbProviderFactories><add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=4.10.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/><add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/> -->
      </system.data>
    
    0 讨论(0)
  • 2020-11-30 06:56

    I Found that removing the references to Entity Framework and installing the latest version of Entity Framework from NuGet fixed the issue. It recreates all the required entries for you during install.

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

    I had the duplicate definition of connection string in my Project Cms.And the Context class is named:CmsContext

    In my case, the problem was solved, as I changed the connectionsting in Web.config as follow:in first one name is CmsContext and it's related to main project .in second one name is DefaultConnection and it's related to Identity

    <add name="CmsContext" providerName="System.Data.SqlClient" connectionString="Data Source=DESKTOP-2NQSP1P\SQLEXPRESS;  Initial Catalog=CmsDB;Integrated Security=True;" />
    </connectionStrings>
    
    0 讨论(0)
  • in my case adding <clear /> just after <connectionStrings> worked like charm

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