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

附加信息:无法加载 文件或程序集 “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相反的参考。

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


当前回答

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

  <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。

我想这会迫使Visual Studio重新加载解决方案和所有项目,重新检查流程中的依赖项。

在我的案例中,这些提议的答案都不起作用。

以下是对我有效的方法:

删除引用 重命名DLL 再次导入引用

第二步显然很重要,因为没有它就不能工作。

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

我遇到了同样的问题,我通过下面的说明解决了它:

打开工具菜单并选择选项 在选项中,窗口转到项目和解决方案/Web项目 检查使用64位版本的IIS…

对我来说,似乎Nuget并没有很好地处理我的项目/解决方案。我用Nuget安装了NewtonSoft。项目文件似乎正确地引用了它,当我在解决方案资源管理器/依赖项/Nuget中r -点击dll名称时,然后单击属性,我发现dll存在于属性说它应该在的地方。

我删除了Nuget包,并做R-click项目>添加>引用,并浏览到包目录中的dll,当以前的Nuget进程已经安装它时,然后解决方案运行良好。

注意:这个解决方案相当大杂烩,首先是Xamarin。iOS解决方案和添加。net标准项目(这是我使用Nuget有困难的地方)。解决方案中还有一个“可移植”项目。我从一个已经离开3年的开发者那里继承了所有这些。哈哈。