.net 无法加载文件或程序集系统找不到指定的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21742777/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:40:05  来源:igfitidea点击:

Could not load file or assembly The system cannot find the file specified

.netvisual-studio-2012dllc++-cli

提问by duggulous

I am building a dll, which references a second dll. I have added the second dll as a reference in the first dll's project by going to Properties > Common Properties > Framework and References > Add New Reference > Browse

我正在构建一个 dll,它引用了第二个 dll。我已经添加了第二个 dll 作为第一个 dll 项目中的引用Properties > Common Properties > Framework and References > Add New Reference > Browse

I compiled the second dll from a third party's source code. Both projects are C++/CLI. Whenever my main application tries to call a function in the first dll which contains a call to the second dll, I get the following error:

我从第三方的源代码编译了第二个 dll。这两个项目都是 C++/CLI。每当我的主应用程序尝试调用包含对第二个 dll 的调用的第一个 dll 中的函数时,我都会收到以下错误:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module.

Additional information: Could not load file or assembly 'NBIS, Version=1.0.5156.29834, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

未知模块中发生类型为“System.IO.FileNotFoundException”的未处理异常。

附加信息:无法加载文件或程序集“NBIS,版本=1.0.5156.29834,Culture=neutral,PublicKeyToken=null”或其依赖项之一。该系统找不到指定的文件。

I have a copy of the second dll in the same directory as my main exe, and I've even tried keeping a copy next to the first dll as well, to no avail.

我在与主 exe 相同的目录中有第二个 dll 的副本,我什至尝试在第一个 dll 旁边保留一个副本,但无济于事。

The second dll references several static libraries, but the only Assembly References it contains are

第二个 dll 引用了几个静态库,但它包含的唯一程序集引用是

System

System.Data

System.Drawing

System.XML

系统

系统数据

系统图

系统文件

All of which I have added as assembly references in the first dll.

我在第一个 dll 中添加了所有这些作为程序集引用。

What can I do to get my application to find and load the second dll?

我该怎么做才能让我的应用程序找到并加载第二个 dll?

回答by Hans Passant

As pointed out in the comments, SysInternals' Process Monitoris a valuable tool to diagnose DLL resolution problems. Tells you when a 3rd party DLL has a dependency you don't know about, also tells you when Windows is looking in the wrong corner of your hard drive for the file or finds the wrong one.

正如评论中所指出的,SysInternals 的Process Monitor是诊断 DLL 解析问题的宝贵工具。当第 3 方 DLL 具有您不知道的依赖项时告诉您,也告诉您 Windows 何时在硬盘驱动器的错误角落查找文件或找到错误的文件。

Loader snapsis the built-in diagnostic tool for Windows. But Process Monitor is far more convenient.

Loader snaps是 Windows 的内置诊断工具。但是进程监视器要方便得多。

It does generate rather a lot of information, start from the bottom of the trace or enable tracing at just the right time. You often need to use its filtering tools to turn the firehose in a relevant trickle. Worth the hour of your time to figure it out, this tool belongs on any programmer's black belt.

它确实生成了相当多的信息,从跟踪的底部开始或在正确的时间启用跟踪。您经常需要使用它的过滤工具将消防水管变成相关的涓涓细流。值得您花一个小时来弄清楚,这个工具属于任何程序员的黑带。

回答by L.W.C. Nirosh

Right click on the project you created the dll and the new referencing project, then select properties. Under Application, check the target framework and verify that both have the same framework, some dll projects tend to select 'client profile' version of the framework by default, which tend to give the error you are having now..

右键单击您创建 dll 的项目和新的引用项目,然后选择属性。在应用程序下,检查目标框架并验证两者是否具有相同的框架,默认情况下,某些 dll 项目倾向于选择框架的“客户端配置文件”版本,这往往会导致您现在遇到的错误。

Let me know if this is not the issue..

如果这不是问题,请告诉我。

回答by PeterX

My PowerShell ISE wasn't running as an Administrator. This seemed to be the problem for me.

我的 PowerShell ISE 没有以管理员身份运行。这似乎是我的问题。

回答by Vijaykumar

Please Change your application pool setting.
Keep the steps:

请更改您的应用程序池设置。
保持步骤:

  1. IIS manager open
  2. Click 'Application pools' (Application pools list)
  3. Select your application pool
  4. Right click your application pool and select 'Advanced settings '
  5. Change 'Enable 32-bit application' from false to true. (When you create application pool Enable 32-bit application default assign false)
  1. IIS管理器打开
  2. 单击“应用程序池”(应用程序池列表)
  3. 选择您的应用程序池
  4. 右键单击您的应用程序池并选择“高级设置”
  5. 将“启用 32 位应用程序”从 false 更改为 true。(创建应用程序池时Enable 32-bit application defaultassign false)

回答by ?????? ????????

For the alert error ("The system cannot find the file specified.")

对于警报错误(“系统找不到指定的文件。”)

  1. Right click on [Solution Program name] then select Build Dependencies> & left click on Build Customizations... then true-checkbox {MASM} then click OK button.

  2. Right click on [Solution Program name] then left click on Properties, left click on "Linker" form "Linker" choose "Debugging" left click on "Debugging" from "Debugging" choose "Debugging Assembly" & convert the value of "Debugging Assembly" to "Yes (/ASSEMBLYDEBUG)", form "Linker" choose "System" left click on "System" from "System" choose "SubSystem" & convert the value of "SubSystem" to "Windows (/SUBSYSTEM:WINDOWS)",, left click on OK button.

  3. Right click on [Solution Program name] then Add> new item, "C++ File(.cpp)" change the name or rename "new item" to "Main.asm" then left click on Add button, Right click on [Main.asm] then left click on Properties select "General" from "General" choose "Item Type" and convert the value of "Item Type" to "Microsoft Macro Assembler" press left click on OK button, then then then Write your assembly code in "Main.asm" file then [[[Debug]]] it using 'step over === F10' from "Debug" tool-bar on top-screen program, all this about how to using assembly code in "Visual Studio 2017".

  1. 右键单击 [Solution Program name],然后选择 Build Dependencies> 并左键单击 Build Customizations... 然后选中 true-checkbox {MASM},然后单击 OK 按钮。

  2. 右键单击[解决方案名称],然后左键单击属性,左键单击“链接器”表单“链接器”选择“调试”左键单击“调试”中的“调试”选择“调试程序集”并转换“调试”的值程序集”为“是(/ASSEMBLYDEBUG)”,形成“链接器”选择“系统”左键单击“系统”从“系统”选择“子系统”并将“子系统”的值转换为“Windows(/SUBSYSTEM:WINDOWS)” ",, 左键单击确定按钮。

  3. 右键单击[Solution Program name] 然后添加> 新项目,“C++ 文件(.cpp)”更改名称或将“新项目”重命名为“Main.asm”,然后左键单击添加按钮,右键单击[Main.asm]。 asm]然后左键单击“属性”从“常规”中选择“常规”选择“项目类型”并将“项目类型”的值转换为“Microsoft Macro Assembler”按左键单击“确定”按钮,然后将您的汇编代码写入“Main.asm”文件然后[[[Debug]]]它使用'step over === F10'从顶部屏幕程序的“Debug”工具栏中,所有这些都是关于如何在“Visual Studio 2017”中使用汇编代码”。