.Net 选择错误引用的程序集版本 [英] .Net picking wrong referenced assembly version

查看:32
本文介绍了.Net 选择错误引用的程序集版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将一个现有项目复制到一台全新的机器上开始开发,但遇到了我引用的一个程序集(一个 Telerik DLL)的版本问题.

I just copied an existing project to a brand new machine to start developing on it and have run into a problem with the version of one of my referenced assemblies (a telerik DLL as it happens).

该项目最初引用了旧版本的程序集(我们称之为 v1.0.0.0).我的新机器安装了最新版本的程序集,所以我想我已经更新了它(我们称之为新版本 v2.0.0.0).

The project originally referenced an older version of the assembly (lets call it v1.0.0.0). My new machine has the latest version of the assembly installed, so I thought I'd updated it (lets call the new version v2.0.0.0).

现在问题来了:如果我将旧的 v1.0.0.0 dll 复制到项目文件夹并将其添加为参考,则网站启动不会出现问题.如果我删除该引用(并从我的系统中删除旧的 DLL)并添加新版本 (v2.0.0.0),该页面将显示以下异常:

Now here's the problem: If I copy the old v1.0.0.0 dll to the project folder and add it as a reference, the web site launches without a problem. If I delete that reference (and also delete the old DLL from my system) and add the new version (v2.0.0.0), the page shows the following exception:

无法加载文件或程序集'XXXXXX,版本=1.0.0.0,文化=中立,PublicKeyToken=121fae78165ba3d4' 或它的依赖项之一.位于程序集的清单定义确实与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)

Could not load file or assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

显然,代码正在寻找过时的版本,但找不到.但为什么?

Clearly, the code is looking for the out of date version and can't find it. But why?

我搜索了该版本号的解决方案文件夹,但找不到任何参考.我仔细检查了 .csproj 文件的文本,发现版本正确显示了最新版本,并且 HintPath 正确显示了新 DLL 的路径.此外,因为我没有在系统上安装旧的 DLL,所以它不会出现在我的 GAC 中(尽管 v2.0.0.0 确实如预期的那样).

I greped the solution folder for that version number and couldn't find a single reference. I double checked the text of the .csproj file and found the version correctly shows the latest version and the HintPath correctly shows the path to the new DLL. Furthermore, because I didn't install the old DLL on the system it doesn't show up in my GAC (though v2.0.0.0 does, as expected).

然后我启用了融合日志查看器,试图找出它为什么要寻找旧版本,但没有运气:

I then enabled the fusion log viewer to try to figure out why it's looking for that old version, but no luck:

Assembly Load Trace: The following information can be helpful to determine why the assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.


=== Pre-bind state information ===
LOG: User = MyCompme
LOG: DisplayName = XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
 (Fully-specified)
LOG: Appbase = file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/
LOG: Initial PrivatePath = d:My DocumentsVisual Studio 2010ProjectsCoolProjWebAppin
Calling assembly : WebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: d:My DocumentsVisual Studio 2010ProjectsCoolProjWebAppweb.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WINDOWSMicrosoft.NETFrameworkv4.0.30319configmachine.config.
LOG: Post-policy reference: XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX/XXXXXX.DLL.
LOG: Attempting download of new URL file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/bin/XXXXXX.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

它说的是从寻找那个旧的程序集开始.我试图在网上找到一个解决方案,看到了类似的 SO 问题,但这似乎与我的问题完全相反.该提问者的程序找到了错误的 DLL 而不是引用的 DLL.而我的问题是该程序神秘地寻找错误的 DLL 并且无法在本地 bin 文件夹和 GAC 中找到正确的 DLL 时找不到它.

All it says it that it starts by looking for that old assembly. I have tried to find a solution online and saw this similar SO question, but it seems to be the exact opposite of my problem. That questioner's program was finding the wrong DLL instead of the referenced one. Whereas my problem is that the program is mysteriously looking for the wrong DLL and unable to find it when the right one can be found locally in the bin folder and in the GAC.

我为什么要找旧版本?我还可以在哪里搜索以找到此错误参考?

Why is mine looking for the old version? Where else can I search to find this bad reference?

推荐答案

我猜你正在使用的另一个程序集正在引用旧的 dll.您是否熟悉正在使用的所有其他项目引用?其中是否有对 Telerik dll 的引用?

My guess is that another assembly you are using is referencing the old dll. Are you familiar with all of the other project references being used and do any of them have a reference to the Telerik dlls?

你能像这样在你的 web.config 文件中加入一个绑定重定向吗?

Can you put in a binding redirect in your web.config file like this?

<dependentAssembly>
 <assemblyIdentity name="Telerik" publicKeyToken="121fae78165ba3d4"/>
 <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>

这篇关于.Net 选择错误引用的程序集版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆