1

我在这里有一个大型项目的 dll 地狱。我有一个 dll 补丁,我试图将其放入程序集中,以便我可以覆盖项目中构建的 dll。我将 .dll 添加到 StartProject 并替换现有的,但我收到以下错误,我不知道为什么会这样。我尝试将特定版本更改为 False,并且每个 dll 的运行时版本看起来都相同。这个 dll 和其他 dll 之间的唯一区别是使用了一个名为 SpecificVersion 的选项 - 但无论如何它都设置为 false。

Failed processing: System.IO.FileLoadException: Could not load file or assembly
XXX.XXX.XXX, Version=X.X.X.X, Culture=neutral, PublicKeyTok
en=5353c9f66d4ed1ec' or one of its dependencies. The located assembly's manifest
 definition does not match the assembly reference. (Exception from HRESULT: 0x80
131040)
File name: 'XXX.XXX.XXX, Version=X.X.X.X, Culture=neutral, P
ublicKeyToken=xxxxxxxxxxxxxxx'
   at XXX.XXX.XXX.XXX.XXX.XX(.....)

我正在查看绑定的 fuslogvw 失败输出,我得到以下信息。抱歉再次编辑。

=== Pre-bind state information ===
LOG: User = X
LOG: DisplayName = DataObjects, Version=0.4.1060.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
 (Fully-specified)
LOG: Appbase = file://X/lib/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Program.exe
Calling assembly : Storage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: DataObjects, Version=0.4.1060.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///X/DataObjects.DLL.
LOG: Assembly download was successful. Attempting setup of file: X\DataObjects.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: DataObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
4

1 回答 1

11

SpecificVersion 仅在您构建项目时才重要。在运行时,CLR 坚持寻找完全匹配。换句话说,最初构建项目时使用的参考程序集的 [AssemblyVersion] 必须与它在运行时找到的 [AssemblyVersion]完全匹配。不匹配是非常危险的,当程序尝试执行程序集中的代码与测试它的代码发生重大变化时,会导致真正的 DLL Hell。

因此,如果您创建一个补丁,那么您必须确保在 AssemblyInfo.cs 源代码文件中声明的 [AssemblyVersion] 属性与原始属性匹配。请确保不要让它自动递增,使用[1.0.*]非常流行并且总是会导致此运行时错误。

您的程序集也是强命名的,PublicKeyToken 值也必须匹配。请务必使用相同的私钥对其进行签名。

使用<bindingRedirect>app.exe.config 文件中的元素是强制 CLR 接受版本不匹配的一种方法。


编辑后:是的,程序集版本显然存在严重不匹配。该应用程序是使用 DataObjects 版本 0.4.1060.0 构建的,但发现版本为 1.0.0.0

于 2013-11-06T15:06:24.013 回答