简体   繁体   English

在 .NET4.5 上安装 EntityFramework5.0.0 后错误:“System.Data.Entity.Internal.AppConfig”的类型初始化程序在运行时引发异常

[英]After installing EntityFramework5.0.0 on .NET4.5 Error: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception at Runtime

I am again raising this question because previous question are unsolved.我再次提出这个问题,因为之前的问题尚未解决。

I have installed EntityFramework 5.0.0 on.Net 4.5 (MVC4), by using a linq query fetching the result of a employee based on id.我已经安装了 EntityFramework 5.0.0 on.Net 4.5 (MVC4),通过使用 linq 查询来获取基于 id 的员工的结果。

public ActionResult Details(int id)
{
    EmployeeContext empctxt = new EmployeeContext();
    Employee employee = empctxt.Employees.Single(emp => emp.employeeid == id);
    return View(employee);
}

Expected to display record of the entered id employee, but giving runtime error as The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.应显示输入的员工 ID 的记录,但运行时错误The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. on the line EmployeeContext empctxt = new EmployeeContext();就行EmployeeContext empctxt = new EmployeeContext();

Web.Config: Web.配置:

<?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=6.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>
  <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>

    <httpRuntime targetFramework="4.5" />

    <compilation debug="true" targetFramework="4.5" />

    <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.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <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></system.webServer>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
<connectionStrings>
  <add name="EmployeeContext" providerName="System.Data.SqlClient" connectionString="SERVER=DESKTOP-DO6F13P;DATABASE=mvctrialdbase;uid=sa;pwd=sa@123;"/>
</connectionStrings>
</configuration>

Problem is in web.config .问题出在web.config中。 While adding Entity Framework the <provider></provider> tag is being added automatically to the web.config file.在添加Entity Framework时, <provider></provider>标签会自动添加到web.config文件中。

Code Added automatically:自动添加代码:

<entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

Therefore <provider></provider> tags need to be delete or has to comment .因此<provider></provider>标签需要被删除或必须评论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server Express “'system.data.entity.internal.appconfig' 的类型初始化程序引发异常”错误 - SQL Server Express “the type initializer for 'system.data.entity.internal.appconfig' threw an exception” error &#39;System.Data.Entity.Internal.AppConfig&#39;的类型初始化程序在子网站上引发了一个例外 - The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception on a Sub Website 未处理typeinitializationexception。&#39;System.Data.Entity.Internal.AppConfig&#39;的类型初始值设定项引发了异常 - typeinitializationexception was unhandled .The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception &#39;System.Data.Entity.Internal.AppConfig&#39;的类型初始值设定项引发了Windows XP的异常 - the type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception for Windows XP System.Data.Entity.MigrateDatabaseToLatestVersion 的类型初始值设定项引发异常 - The type initializer for System.Data.Entity.MigrateDatabaseToLatestVersion threw an exception 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' 的类型初始值设定项抛出异常 - The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception &#39;System.Data.Entity.Migrations.DbMigrationsConfiguration`1&#39;的类型初始值设定项引发了Oracle数据库异常 - The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception with Oracle Database System.Data.SqlClient的类型初始值设定项引发了异常 - type initializer for System.Data.SqlClient threw an exception &#39;&#39;的类型初始值设定项引发了异常 - The type initializer for '' threw an exception 类型初始值设定项引发异常 - Type initializer threw an exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM