加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用EF5从4.5降级到4.0后无法加载文件或程序集“Enti

发布时间:2020-12-15 21:00:39 所属栏目:asp.Net 来源:网络整理
导读:我最近使用Entity Framework 5开发了一个.net 4.5库.一切正常,直到我被告知我必须降级到.net 4.0才能与 Windows 2003保持兼容. 我使用程序包管理器控制台卸载了EF 5并获得了成功的消息,然后这个消息: Failed to generate binding redirects for 'MyProjectN
我最近使用Entity Framework 5开发了一个.net 4.5库.一切正常,直到我被告知我必须降级到.net 4.0才能与 Windows 2003保持兼容.

我使用程序包管理器控制台卸载了EF 5并获得了成功的消息,然后这个消息:

Failed to generate binding redirects for 'MyProjectName'. An item with the same key has already been added.

降级和安装Entity Framework后会出现相同的消息.

一切都在编译.但是在执行时我有这个例外:

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

Could not load file or assembly 'EntityFramework,Version=5.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,PublicKeyToken=b77a5c561934e089"

在Web.Config(以及库的App.Config)中,我有以下几行:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
...
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"
                      culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
   </assemblyBinding>
</runtime>

任何帮助,将不胜感激.

解决方法

由于另一个话题,我终于解决了这个问题: could-not-load-file-or-assembly-entityframework-after-downgrading-ef-5-0-0-0

尽管我使用Package Manager Console安装了EF 5软件包. .Net 4.0的实体框架的实际版本是4.4版.我已经改变了配置文件中的值,它确实有效!

<section name="entityFramework"
    type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,Version=4.4.0.0,PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
...
<dependentAssembly>
    <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089"
    culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0"/>
</dependentAssembly>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读