定位程序集的清单定义与程序集引用C#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=XXXX, 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=XXXX, 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. 

SpecificVersion仅在构建项目时很重要。 在运行时,CLR坚持找到完全匹配。 换句话说,最初构建项目时使用的引用程序集的[AssemblyVersion]必须与它在运行时找到的[AssemblyVersion] 完全匹配。 不匹配是非常危险的,当程序试图执行程序集中的代码时,会导致真正的DLL Hell,而代码程序中的代码实际上已经从测试的代码中发生了变化。

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

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

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


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