简体   繁体   English

从实体框架获取错误(类型初始化器异常)

[英]Getting an error from Entity Framework(type initializer exception)

I' am getting this: 我得到这个:

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. “ System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发了异常。

error in my Entity Framework. 我的实体框架出现错误。

I read this Question and the possible answers, however non of them worked for me. 我读了这个问题和可能的答案,但是没有一个对我有用。 Here is my App.config file: 这是我的App.config文件:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

  <connectionStrings>
    <add name="SalesReportEntities" 
         connectionString="metadata=res://*/SalesReportModel.csdl
                         |res://*/SalesReportModel.ssdl
                         |res://*/SalesReportModel.msl;
                         provider=System.Data.SqlClient;
                         provider connection string=&quot;data source=.;
                                                    initial catalog=Training;
                                                    integrated security=True;
                                                    MultipleActiveResultSets=True;
                                                    App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework> 
</configuration>

What other possible things can cause this error? 还有哪些其他可能的原因导致此错误?

I can offer a few suggestions and some are similar to the thread you already looked at: 我可以提供一些建议,其中一些与您已经看过的线程类似:

  1. Can you use SQL Management Studio and verify this database exists and has tables and is currently in a responsive state? 您可以使用SQL Management Studio并验证此数据库是否存在并具有表并且当前处于响应状态吗?
  2. Put your 'connectionStrings' section after the < providers > node. 将您的“ connectionStrings”部分放在<providers>节点之后。
  3. Your parameter value is 'v11.0' which seems to be targeting a version of SQL Server 2012. Mine that I am looking at now is similar to yours but just states: "mssqllocaldb". 您的参数值是“ v11.0”,它似乎针对的是SQL Server 2012版本。我现在正在查看的矿井与您的矿井相似,但仅声明:“ mssqllocaldb”。 Which I believe is just the default instance of sql server from the connection you specify. 我相信这只是您指定的连接中sql server的默认实例。
  4. Uninstall Entity Framework completely and get it again from NuGet. 完全卸载Entity Framework,然后从NuGet重新获取。 I assume you are using Visual Studio so in 2015 it is Tools>NuGet Package Manager>Manage NuGet Packages. 我假设您使用的是Visual Studio,因此在2015年,它是“工具”>“ NuGet程序包管理器”>“管理NuGet程序包”。 Uninstall, check your app config and 'References' that 'EntityFramework' is gone. 卸载后,检查您的应用程序配置,并且“参考”中的“ EntityFramework”已消失。 Reinstall and check your settings again. 重新安装并再次检查您的设置。
  5. Are you trying to reference a project that entity lives in in another project or is it self contained? 您是否正在尝试引用一个实体存在于另一个项目中的项目,或者该项目是自包含的? If so you need to target EF just like you were on the source project with adding EF to that project and a config the same. 如果是这样,您需要像在源项目上一样将EF定位为目标,只需将EF添加到该项目并对其进行配置即可。

You may also want to post the entire exception for better answers too. 您可能还希望发布整个异常,以获得更好的答案。

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

相关问题 实体框架类型初始化程序异常 - Entity Framework type initializer exception SQL Server Express “'system.data.entity.internal.appconfig' 的类型初始化程序引发异常”错误 - SQL Server Express “the type initializer for 'system.data.entity.internal.appconfig' threw an exception” error C#错误“…的类型初始值设定项引发了异常 - C# Error "The type initializer for … threw an exception 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 在 .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 &#39;&#39;的类型初始值设定项引发了异常 - The type initializer for '' threw an exception 类型初始化器异常@ Mutex - Type Initializer Exception @ Mutex 类型初始值设定项引发异常 - Type initializer threw an exception MemCache类型初始化程序异常 - MemCache Type Initializer Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM