定位的程序集的清单定义与程序集引用不匹配 C# Dll 地狱
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19811009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The located assembly's manifest definition does not match the assembly reference C# Dll hell
提问by disruptive
I'm in dll hell here with a large project. I have a dll patch which I'm trying to put into the assembly such that I can overide the built dlls in the project. I'm adding the .dll to the StartProject and replacing the existing one, but I get the following error and I don't know why this is the case. I've tried changing the specific version to False and the runtime versions all look identical for each of the dll's. The only difference in properties between this dll and the others is the use of an option called SpecificVersion - but this is set to false anyway.
我在这里有一个大项目的 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(.....)
I'm looking at the fuslogvw failure output for binding and I get the following. Sorry for Redacting again.
我正在查看绑定的 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.
回答by Hans Passant
SpecificVersion only matters when you build your project. At runtime, the CLR insists on finding an exactmatch. In other words, the [AssemblyVersion] of the reference assembly that was used when the project was originally built must be an exactmatch with the [AssemblyVersion] it finds back at runtime. A mismatch is very dangerous, causing true DLL Hell when the program tries to execute code in the assembly that substantially changed from the code it was tested against.
特定版本仅在您构建项目时才重要。在运行时,CLR 坚持寻找精确匹配。换句话说,最初构建项目时使用的参考程序集的 [AssemblyVersion] 必须与它在运行时找到的 [AssemblyVersion]完全匹配。不匹配是非常危险的,当程序尝试执行程序集中的代码时,它会导致真正的 DLL 地狱,而这些代码与测试所针对的代码有很大不同。
So if you create a patch then you must be sure that the [AssemblyVersion] attribute as declared in the AssemblyInfo.cs source code file matches the original. Do make sure that you don't let it increment automatically, using [1.0.*]
is pretty popular and will always cause this runtime error.
因此,如果您创建补丁,则必须确保在 AssemblyInfo.cs 源代码文件中声明的 [AssemblyVersion] 属性与原始属性匹配。请确保不要让它自动增加,使用[1.0.*]
非常流行并且总是会导致此运行时错误。
Your assembly is also strong-named, the PublicKeyToken value must match as well. Be sure to sign it with the same private key.
您的程序集也是强命名的,PublicKeyToken 值也必须匹配。请务必使用相同的私钥对其进行签名。
Using a <bindingRedirect>
element in the app.exe.config file is a way to force the CLR to accept a version mismatch.
使用<bindingRedirect>
app.exe.config 文件中的元素是一种强制 CLR 接受版本不匹配的方法。
After edit: yes, there's clearly a gross mismatch in the assembly version. The app was built with DataObjects version 0.4.1060.0 but found version 1.0.0.0
编辑后:是的,汇编版本中显然存在严重不匹配。该应用程序使用 DataObjects 版本 0.4.1060.0 构建,但发现版本为 1.0.0.0