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

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

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


当前回答

我有一个c# Winforms项目,名为SetTags,其中有大量的表单,我使用Visual Studio 2013来处理。在编辑其中一个并尝试构建后,我得到了错误:

Could not load file or assembly 'SetTags Version = 2.1.85.0, Culture=neutral,PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

当我试图保存项目或关闭一直在处理的表单时,也出现了错误。

我通过删除最近添加的单选按钮控件并注释掉对它的所有引用来解决这个问题,然后再次添加该控件并取消注释代码。这让我可以保存表单,在关闭重新启动VS时,问题已经消失了。

我的Visual Studio环境偶尔有很多问题——工具箱不显示或只在VS启动时出现,在设计模式下查看表单时无法识别自定义控件——这可能是我需要转移到后面的VS版本。

其他回答

您的项目的csproj文件必须包含Microsoft.Practices.Unity的包引用,在global-packages文件夹(%userprofile%.nuget\packages)中找不到,运行dotnet还原可以解决这个问题

在99%时,无法加载文件或程序集或其依赖项之一的问题是由依赖项引起的!我建议你遵循以下步骤:

从http://www.dependencywalker.com/下载Dependency Walker 启动Dependency Walker并打开dll(在我的例子中是NativeInterfaces.dll) 您可以看到一个或多个dll的错误在红色错误打开文件…

这意味着这个dll在你的系统中丢失了;在我的情况下,dll名称是MSVCR71.DLL 您可以从谷歌下载丢失的dll,并复制到正确的路径(在我的情况下c:\windows\system32) 此时,您必须在GAC(全局程序集缓存)中注册新的dll:打开DOS终端并写入: cd \ Windows \ System32系统 Regsvr32 /i msvcr71.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

我的解决方案是:

我有一个三层应用程序,我忘记将DLL复制到IIS的正确路径。只要复制到正确的位置,它就为我工作了。

在解决方案资源管理器中右键单击项目(不是解决方案),在构建选项卡中选择平台目标:“任何CPU”。