Asp.net 无法加载文件或程序集';实体框架&x27;使用EF5从4.5降到4.0后
我最近使用EntityFramework5开发了一个.NET4.5库。在我被告知必须降级到.NET4.0才能与Windows2003兼容之前,一切都很顺利 我使用Package Manager控制台卸载了EF 5,并显示成功消息,然后是以下消息:Asp.net 无法加载文件或程序集';实体框架&x27;使用EF5从4.5降到4.0后,asp.net,.net,entity-framework,Asp.net,.net,Entity Framework,我最近使用EntityFramework5开发了一个.NET4.5库。在我被告知必须降级到.NET4.0才能与Windows2003兼容之前,一切都很顺利 我使用Package Manager控制台卸载了EF 5,并显示成功消息,然后是以下消息: Failed to generate binding redirects for 'MyProjectName'. An item with the same key has already been added. 降级和安装实体框架后会出现相同的消
Failed to generate binding redirects for 'MyProjectName'. An item with the same key has already been added.
降级和安装实体框架后会出现相同的消息
一切都在编译。但在执行时,我有一个例外:
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, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
在Web.Config(和库的App.Config)中,我有以下几行:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, 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>
...
感谢您的帮助。多亏了另一个主题,我终于解决了这个问题: 尽管我用PackageManager控制台安装了EF5软件包。Net 4.0实体框架的实际版本是4.4版。我已经更改了配置文件中的值,并且成功了
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=4.4.0.0, Culture=neutral,
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>
...
使用Nuget卸载EF,然后再次添加它,清理并重建项目。如果您在项目中添加了实体框架的引用,请删除并重新添加对新dll的引用,然后重建,但我没有帮助。问题的另一部分是entity framework 4.0与.net一起提供,5.0与.net分离,并作为nuget package提供。如果有人在挖掘,如果您特别要求package manager安装EF 4.4,它会告诉您该版本不存在。