c# - 如何修复异常无法加载文件或程序集 'EntityFramework, Version=4.0.0.0[...]' 或其依赖项之一

标签 c# .net entity-framework

我安装了 EF6,然后意识到 MySQL 尚未在其连接器/网络上为其提供支持。所以很自然地我回滚了,现在我得到了标题中引用的错误。

我的 app.config 看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.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>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

我的引用资料如下:

名称: EntityFramework.dll
创建者: Microsoft Corporation
版本: 5.0.20627.0

此外,我还引用了以下程序集:

名称:System.Data
版本:4.0.0.0
文件版本:4.030319.17929

名称:System.Data.Entity
版本:4.0.0.0
文件版本:4.030319.17929

我得到的异常的确切文本是:

An error occurred creating the configuration section handler for entityFramework: Could not load file or assembly 'EntityFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我该如何解决这个问题??

最佳答案

您的配置引用版本和安装的版本不匹配。您应该更改以下代码行,因为您引用的是 entityframework 版本 5.0.0.0 dll。所以只需尝试替换以下代码行即可。

<section name="entityFramework" 
          type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
          requirePermission="false" />

关于c# - 如何修复异常无法加载文件或程序集 'EntityFramework, Version=4.0.0.0[...]' 或其依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721167/

相关文章:

c# - Entity Framework 试图创建重复的列

c# - 将 ObservableCollection<string> 双向绑定(bind)到 WPF DataGrid

javascript - 如何在 booking.com 等谷歌地图上显示自己的属性列表

c# - 如何在 C# 中撤消和重做(富文本框)

c# - 方法链接的最佳实践 ("return this")

c# - .NET Entity Framework 插入与批量插入

c# - 将 JSON 转换为 C# 复杂对象

c# - 如何使用 Watin 关闭浏览器 (IE8)?

c# - Winforms 文本框的焦点丢失事件?

asp.net-mvc - Entity Framework 错误 - 同时读取数据库