System.IO.FileNotFoundException:部署应用程序时无法加载文件或程序集“X"或其依赖项之一 [英] System.IO.FileNotFoundException: Could not load file or assembly 'X' or one of its dependencies when deploying the application

查看:51
本文介绍了System.IO.FileNotFoundException:部署应用程序时无法加载文件或程序集“X"或其依赖项之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在部署一个应用程序时遇到了一个奇怪的问题,该应用程序引用了一个用托管 C++ 编写的程序集.

I'm having a strange problem with deploying an application, which references an assembly, written in managed c++.

我创建了一个程序集 X,编译它并在一个名为 Starter 的 exe 文件中引用它.

I've created an assembly X, compiled it and referenced it in an exe file, called Starter.

Starter.exe 在本地机器上正常启动.但是,当我将 starter 调试文件夹的所有内容复制到虚拟机并尝试在那里启动时,它会崩溃并出现以下异常:

Starter.exe starts normally on local mashine. 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:

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

这对我来说没有任何意义,因为 X 与 Starter.exe 位于同一文件夹中.

This does not make any sense to me, because X is right in the same folder as Starter.exe.

可能导致此问题的原因是什么?

What could be causing this problem?

更新

我已经检查了目标机器上 Reflector 中的依赖项,它能够找到所有这些的文件.

I've examined the dependencies in Reflector on the target machine, and it was able to find files for all of those.

我还将所有项目的配置更改为 x86/win32.

I've also changed the configurations to x86/win32 for all projects.

更新

以下是 Fusion Log 的日志(位置:C:FusionLogDefaultStarter.exeX,Version=1.0.4538.22813,Culture=neutral,PublicKeyToken=null.HTM):

Here are the logs from Fusion Log (location: C:FusionLogDefaultStarter.exeX, 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:WINDOWSMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable  C:Documents and SettingsAdministratorDesktop	mpk;kStarter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827Administrator
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 SettingsAdministratorDesktop	mpk;kStarter.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WINDOWSMicrosoft.NETFrameworkv4.0.30319configmachine.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 SettingsAdministratorDesktop	mpk;kX.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 SettingsAdministratorDesktop	mpk;kX.dll.
LOG: Assembly is loaded in default load context.

唯一的错误在 C:FusionLogNativeImageStarter.exe 目录:

The only errors are in C:FusionLogNativeImageStarter.exe directory:

*** 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:WINDOWSMicrosoft.NETFrameworkv4.0.30319clr.dll
Running under executable  C:Documents and SettingsAdministratorDesktop	mpk;kStarter.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = MENKAUR-7683827Administrator
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 SettingsAdministratorDesktop	mpk;kX.dll.

我无法对程序集进行签名,因为它引用了其他几个未签名的程序集

I cannot sign the assembly, as it references several other assemblies, which are not signed

推荐答案

... 无法加载文件或程序集X"或其依赖项之一...

很可能无法加载另一个依赖项.

Most likely it fails to load another dependency.

您可以尝试使用依赖项检查器检查依赖项.

you could try to check the dependencies with a dependency walker.

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

还要检查您的构建配置 (x86/64)

Also check your build configuration (x86 / 64)

当我从不受信任的"文件复制 zip 中的 dll 时,我也遇到过这个问题.网络共享.文件被 Windows 锁定,引发了 FileNotFoundException.

I also had this problem once when I was copying dlls in zip from a "untrusted" network share. The file was locked by Windows and the FileNotFoundException was raised.

参见此处:检测到的 DLL来自互联网并被阻止"作者:CASPOL

这篇关于System.IO.FileNotFoundException:部署应用程序时无法加载文件或程序集“X"或其依赖项之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆