【问题标题】:Entity Framework version error in my small code first project我的小代码第一个项目中的实体框架版本错误
【发布时间】:2012-07-12 00:32:01
【问题描述】:

我正在编写一个小型测试项目,以便首先了解 EF 代码。不幸的是,当我尝试编译时,出现以下错误:

Assembly 'Backend, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses   
'EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'  
which has a higher version than referenced assembly 'EntityFramework, Version=4.1.0.0,  
Culture=neutral, PublicKeyToken=b77a5c561934e089'   c:\Users\Kevin\Documents\Visual   
Studio 2010\Projects\CFTest\Backend\bin\Debug\Backend.dll   CFTest

由于某种原因,存在版本冲突,但我不知道如何解决。

编辑:我的 App.config:

<?xml version="1.0" encoding="utf-8"?>
<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=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

【问题讨论】:

    标签: asp.net-mvc-3 c#-4.0 entity-framework-4.1 ef-code-first entity-framework-4.3


    【解决方案1】:

    我的后端项目有一个版本的 EF,而我的 MVC 项目默认有另一个版本。解决了。​​

    【讨论】:

    • 感谢您添加解决方案。现在我想起来了,我以前用同样的分辨率遇到过同样的问题。谢谢。
    • 它在错误消息中非常清楚 - 后端有 4.3,编译期间的 Web 项目显示 4.3.1。您可以删除两者并简单地在两者上执行安装包实体框架(或使用 -pre 获取 EF 5 RC 代码)
    • 是的,但我没有意识到我的 MVC 3 项目预加载了对 EF 4.1 的引用(我使用了默认项目,而不是空项目)。后端是一个单独的 C# 类库项目,我在其中显式安装了对 4.3.1 的引用。因此,我的显式 EF 引用与默认安装的一个 VS 之间存在冲突,它跨越了两个项目。但是无所谓。现在已经解决了,这是一个教训。
    【解决方案2】:

    它与您的项目正在使用的 .NET Framework 版本以及编译 EF dll 的 .NET Framework 版本冲突。如果您转到项目的添加引用窗口,列表应该说明每个 DLL 使用的 .NET Framework 版本。更改您的项目目标以使用该版本。

    【讨论】:

    • 我的项目面向 .NET 4,就像 DLL 一样
    • 也许有人正在使用客户端配置文件版本?这可能会导致冲突。你 100% 确定 dll 使用 4.0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多