定位程序集的清单定义与程序集引用C#Dll地狱不匹配

dis*_*ive 1 c# dll visual-studio-2012

我在这里遇到一个大型项目.我有一个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(.....)
Run Code Online (Sandbox Code Playgroud)

我正在查看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.
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 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