13

在过去的 12 个小时里,我一直在尝试解决程序集绑定问题,但运气不佳。上周,我已将解决方案中的所有项目从 EF 4.1.0.0 升级到 EF 4.3.1.0。今天早上我在一个现有的测试项目中添加了一些测试,清理并重新编译了解决方案。所有项目都编译时没有警告或错误。在项目中任何地方的实体框架调用中,我收到以下异常:

初始化方法 NutricityPPCTests.Common.DizzleProductExtensionsTests.TestSetup 抛出异常。System.IO.FileLoadException:System.IO.FileLoadException:无法加载文件或程序集“EntityFramework,Version=4.1.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)。

我启动了融合程序集绑定日志查看器,并找到了与异常对应的日志条目。我已经验证我的测试项目 MOMData 项目都引用了正确的 EF4.3.1.0 程序集。我确认项目文件中没有对 EF 4.1.0.0 的引用。我删除了两个项目中的 obj 和 bin 目录的内容。这个项目已经清理和重建了很多次,我的硬盘可能明天就要报废了。

*** Assembly Binder Log Entry  (3/22/2012 @ 5:55:11 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\QTAgent32.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NUTRICITY0\awolske
LOG: DisplayName = EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Users/awolske/Documents/NutricityWorkspace/Nutricity/NutricityPPCTests/bin/Release
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = QTAgent32.exe
Calling assembly : MomData, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\awolske\Documents\NutricityWorkspace\Nutricity\NutricityPPCTests\bin\Release\NutricityPPCTests.DLL.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/awolske/Documents/NutricityWorkspace/Nutricity/NutricityPPCTests/bin/Release/EntityFramework.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\awolske\Documents\NutricityWorkspace\Nutricity\NutricityPPCTests\bin\Release\EntityFramework.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我还应该在哪里寻找旧的引用程序集?!?欢迎任何帮助,并非常感谢!在此先感谢您的时间!

4

2 回答 2

17

将以下内容添加到您的 web.config 文件中:

<runtime>
<assemblyBinding>
        <dependentAssembly>
          <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
        </dependentAssembly>
   </assemblyBinding>
</runtime>
于 2012-05-27T16:38:28.933 回答
1

我有同样的错误。我的解决方案中的大多数项目都引用了 Entity Framework 4.3.0.0 dll,但是当我检查解决方案中所有项目的引用时,我发现一些项目引用了 Entity Framework 4.1.0.0 dll。删除并用对实体框架 4.3.0.0 dll 的新引用替换它们解决了这个问题。

于 2012-04-04T10:36:57.370 回答