我有另一个这些“无法加载文件或程序集或其依赖项之一”的问题。

附加信息:无法加载 文件或程序集 “Microsoft.Practices.Unity, Version = 1.2.0.0、文化=中立, 都31 bf3856ad364e35”或 它的依赖项之一。在位于 程序集的显式定义可以 不匹配程序集引用。 (异常来自HRESULT: 0x80131040)

我不知道是什么导致了这种情况,也不知道如何调试它来找到原因。

我在我的解决方案目录.csproj文件中做了一个搜索,我有Unity的每个地方:

参考 包括= " Microsoft.Practices.Unity, Version = 2.0.414.0、文化=中立, 都31 bf3856ad364e35, processorArchitecture = MSIL”

在我的任何项目中都找不到任何与1.2.0.0相反的参考。

我该怎么解决这个问题呢?


当前回答

我在这个问题上也浪费了几个令人沮丧的小时。我们不得不更新我们的. net框架版本,并开始得到多个“无法加载文件或程序集或其依赖项之一”的dll,这些dll多年未更改。奇怪的是,在错误消息中搜索的版本都非常旧。例如,它正在搜索Newtonsoft。Json版本为6.0.0,而我们已经使用8.0.1很多年了。

回到这些古老的版本不是一个选择,无论如何,在我们的网络中有一堆bindingRedirect元素。配置文件,应该重定向到旧dll到新dll的调用。回滚。net版本可以消除这些错误,但我们需要新版本。这是怎么回事?

web中的<runtime>元素。配置文件包含元素:

<assemblyBinding appliesTo="v2.0.50727"
    xmlns="urn:schemas-microsoft-com:asm.v1">

似乎被忽略的dependentAssembly元素包含在其中。

罪魁祸首是appliesTo属性。这意味着bindingRedirect只应用于. net 2.0.50727版本。当我们更新. net Framework版本时,我们所有的bindingRedirect元素都被忽略了。

在我们的案例中,解决方案是完全删除appliesTo属性。

其他回答

TLDR; 我的解决方案是在visual studio中恢复默认设置。


我在visual studio 2019社区版上,我在不同的项目中遇到了同一个dll文件的问题,我没有接触过。

After trying out all the answers in this question (as of 2020-07-22 7:13UTC) I decided to repair visual studio installation (backed up my settings beforehand). After installation opened the solutions that had the problem and the problem was gone. After that imported my settings that and the problem came back!! So without repairing visual studio installation again (which takes a few minutes + one restart) I've simply restored VS default settings and then it works. If I end up having time to investigate, I'll edit the answer and pinpoint the underlaying issue

在我的情况下,bin文件夹是一个名为Unity的非引用dll。MVC3,我试图在visual studio中搜索任何参考,没有成功,所以我的解决方案很简单,从bin文件夹中删除那个dll。

我今天遇到了这个问题,对我来说,这个问题非常奇怪:

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0" newVersion="3.1.0.0" />
  </dependentAssembly>0.

注意XML末尾的零散字符——不知怎么的,这些字符已经从版本号移到了这个XML块的末尾!

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Host.SystemWeb" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>

改成上面的,瞧!一切都恢复正常了。

尽管最初的问题是五年前发布的,但这个问题仍然存在,而且相当烦人。

一般的解决方案是彻底分析所有引用的程序集,以了解哪里出了问题。为了使这个任务更容易,我做了一个工具(一个Visual Studio扩展),它允许选择一个. net程序集(一个.dll或.exe文件)来获得所有引用程序集的图形,同时突出显示冲突或缺失的引用。

该工具可在Visual Studio Gallery中获得:https://marketplace.visualstudio.com/vsgallery/051172f3-4b30-4bbc-8da6-d55f70402734

输出示例:

下面的方法对我很有效。

删除临时文件C:\Windows\Microsoft.NET\Framework\v4.0.30319\临时ASP. net网络文件 关闭VSTS,然后重新打开 删除和添加相同的dll(注意:您添加了相同的匹配版本)