简体   繁体   English

System.IO.FileNotFoundException:部署应用程序时无法加载文件或程序集“X”或其依赖项之一

[英]System.IO.FileNotFoundException: Could not load file or assembly 'X' or one of its dependencies when deploying the application

I'm having a strange problem with deploying an application, which references an assembly, written in managed c++.我在部署一个应用程序时遇到了一个奇怪的问题,该应用程序引用了一个用托管 C++ 编写的程序集。

I've created an assembly X, compiled it and referenced it in an exe file, called Starter.我创建了一个程序集 X,编译它并在一个名为 Starter.exe 的 exe 文件中引用它。

Starter.exe starts normally on local mashine. Starter.exe 在本地机器上正常启动。 However, when I copy ALL contents of the starter debug folder to a virtual mashine, and try to start it there, it crashes with following exception:但是,当我将 starter 调试文件夹的所有内容复制到虚拟机并尝试在那里启动它时,它会崩溃并出现以下异常:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or 
assembly 'X' or one of its dependencies. The specified module could not be found.

This does not make any sense to me, because X is right in the same folder as Starter.exe.这对我来说没有任何意义,因为 X 与 Starter.exe 位于同一文件夹中。

What could be causing this problem?什么可能导致这个问题?

UPDATE更新

I've examined the dependencies in Reflector on the target machine, and it was able to find files for all of those.我已经检查了目标机器上 Reflector 中的依赖项,它能够找到所有这些的文件。

I've also changed the configurations to x86/win32 for all projects.我还将所有项目的配置更改为 x86/win32。

UPDATE更新

Here are the logs from Fusion Log (location: C:\\FusionLog\\Default\\Starter.exe\\X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.HTM):以下是 Fusion Log 中的日志(位置:C:\\FusionLog\\Default\\Starter.exe\\X,Version=1.0.4538.22813,Culture=neutral,PublicKeyToken=null.HTM):

*** Assembly Binder Log Entry  (6/4/2012 @ 1:56:13 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/X.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.
LOG: Assembly is loaded in default load context.

The only errors are in C:\\FusionLog\\NativeImage\\Starter.exe\\ directory:唯一的错误在 C:\\FusionLog\\NativeImage\\Starter.exe\\ 目录中:

*** Assembly Binder Log Entry  (6/4/2012 @ 1:56:13 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = BookmarkWiz.Kernel, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start binding of native image X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.

I cannot sign the assembly, as it references several other assemblies, which are not signed我无法对程序集进行签名,因为它引用了其他几个未签名的程序集

... Could not load file or assembly 'X' or one of its dependencies ... ... 无法加载文件或程序集“X”或其依赖项之一...

Most likely it fails to load another dependency.它很可能无法加载另一个依赖项。

you could try to check the dependencies with a dependency walker.您可以尝试使用依赖项walker检查依赖项。

Ie: https://www.dependencywalker.com/即: https : //www.dependencywalker.com/

Also check your build configuration (x86 / 64)还要检查您的构建配置(x86 / 64)

Edit: I also had this problem once when I was copying dlls in zip from a "untrusted" network share.编辑:当我从“不受信任的”网络共享复制 zip 中的 dll 时,我也遇到过这个问题。 The file was locked by Windows and the FileNotFoundException was raised.该文件已被 Windows 锁定,并引发了 FileNotFoundException。

See here: Detected DLLs that are from the internet and "blocked" by CASPOL请参阅此处: 检测到的来自 Internet 并被 CASPOL“阻止”的 DLL

I resolved this problem by renaming the DLL.我通过重命名 DLL 解决了这个问题。 The DLL had been manually renamed when it was uploaded to its shared location (a version number was appended to the file name). DLL 在上传到共享位置时已被手动重命名(在文件名后附加了版本号)。 Removing the version number from the downloaded file resolved the issue.从下载的文件中删除版本号解决了该问题。

I had the same issue.我遇到过同样的问题。 For me it helped to remove the .vs directory in the project folder.对我来说,它有助于删除项目文件夹中的 .vs 目录。

I also had the same issue when I tried to install a Windows service, in my case I managed to resolved the issue by removing blank spaces in the folder path to the service .exe, below is the command worked for me in a command prompt当我尝试安装 Windows 服务时,我也遇到了同样的问题,在我的情况下,我设法通过删除服务 .exe 的文件夹路径中的空格来解决这个问题,下面是在命令提示符下为我工作的命令

cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319

Press ENTER to change working directory按 ENTER 更改工作目录

InstallUtil.exe C:\\MyService\\Release\\ReminderService.exe

Press ENTER按 ENTER

For me, I started the app from within windows explorer (by double clicking on it).对我来说,我从 Windows 资源管理器中启动了该应用程序(通过双击它)。 Then it crashed immediately.然后它立刻崩溃了。

I then opened Event Viewer of windows and viewed Application and it displayed full stacktrace of error.然后我打开了窗口的Event Viewer并查看了Application ,它显示了完整的错误堆栈跟踪。 The stacktrace showed relation with Bitmap or images.堆栈跟踪显示与位图或图像的关系。 It was then turned out to be due to app icon not found后来证明是因为找不到应用程序图标

's up guys i read every single forum about this topic i still had problem (occurred trying to project from git)伙计们,我阅读了有关此主题的每个论坛,但仍然遇到问题(尝试从 git 进行项目时发生)

after 4 hours and a lot of swearing i solved this issue by myself just by changing target framework setting in project properties (right click on project -> properties) -> application and changed target framework from .net core 3.0 to .net 5.0 i hope it will help anybody经过 4 个小时和大量的咒骂,我自己解决了这个问题,只是通过更改项目属性中的目标框架设置(右键单击项目 -> 属性)-> 应用程序并将目标框架从 .net core 3.0 更改为 .net 5.0 我希望它会帮助任何人

happy coding gl hf nerds快乐编码 gl hf 书呆子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.IO.FileNotFoundException:无法加载文件或程序集“程序集名称”或其依赖项之一 - System.IO.FileNotFoundException: Could not load file or assembly 'name of assembly' or one of its dependencies 了解 CLR/System.IO.FileNotFoundException “无法加载文件或程序集......或其依赖项之一” - understanding CLR/System.IO.FileNotFoundException "Could not load file or assembly ... or one of its dependencies" 如何修复 System.IO.FileNotFoundException:无法加载文件或程序集“ScanAPIHelper.dll”或其依赖项之一 - How to fix System.IO.FileNotFoundException: Could not load file or assembly 'ScanAPIHelper.dll' or one of its dependencies 无法加载文件或程序集System.IO.FileNotFoundException - Could not load file or assembly System.IO.FileNotFoundException System.IO.FileNotFoundException:无法加载文件或程序集 - System.IO.FileNotFoundException: Could not load file or assembly System.IO.FileNotFoundException: '无法加载文件或程序集 - System.IO.FileNotFoundException: 'Could not load file or assembly 奇怪的错误:System.IO.FileNotFoundException:无法加载文件或程序集 - Weird Error: System.IO.FileNotFoundException: Could not load file or assembly System.IO.FileNotFoundException: 无法加载文件或程序集 C# - System.IO.FileNotFoundException: Could not load file or assembly C# NUnit测试由于“ System.IO.FileNotFoundException:无法加载文件或程序集X”而无法运行 - NUnit Tests won't run because of “System.IO.FileNotFoundException : Could not load file or assembly X” OmniSharp 服务器抛出 System.IO.FileNotFoundException:打开 Unity 项目时无法加载文件或程序集 'netstandard - OmniSharp server throws System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, When Opening Unity Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM