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

前端之家收集整理的这篇文章主要介绍了asp.net – 使用EF5从4.5降级到4.0后无法加载文件或程序集“EntityFramework”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最近使用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>

猜你在找的asp.Net相关文章