先。在部署应用程序时,不能加载文件或程序集的X或它的一个依赖项。

时间:2022-09-01 11:28:15

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,编译它并在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:

起动器。exe通常在当地的mashine上启动。但是,当我将starter debug文件夹的所有内容复制到一个虚拟的mashine中,并尝试在那里启动它时,它会发生以下异常:

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.

我已经检查了目标机器上反射器的依赖关系,并且它能够为所有这些文件找到文件。

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):

这里是来自FusionLog(位置:C:\FusionLog\Default\Starter)的日志。exe \ X,Version = 1.0.4538.22813文化=中立,都必须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

我不能在程序集上签名,因为它引用了其他几个没有签名的程序集。

3 个解决方案

#1


12  

... 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的依赖项。

I.e: http://www.dependencywalker.com/

我。艾凡:http://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. The file was locked by Windows and the FileNotFoundException was raised.

编辑:当我从一个“不受信任”的网络共享拷贝dll时,我也有过这个问题。文件被Windows锁定,而FileNotFoundException被提高。

See here: Detected DLLs that are from the internet and "blocked" by CASPOL

参见这里:检测到来自互联网的dll和CASPOL的“阻塞”。

#2


2  

I resolved this problem by renaming the DLL. The DLL had been manually renamed when it was uploaded to its shared location (a version number was appended to the file name). Removing the version number from the downloaded file resolved the issue.

我通过重新命名DLL来解决这个问题。当它被上传到它的共享位置时,DLL就被手工重命名了(一个版本号被附加到文件名)。从下载的文件中删除版本号解决了这个问题。

#3


1  

I had the same issue. For me it helped to remove the .vs directory in the project folder.

我有同样的问题。对我来说,它有助于删除项目文件夹中的.vs目录。

#1


12  

... 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的依赖项。

I.e: http://www.dependencywalker.com/

我。艾凡:http://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. The file was locked by Windows and the FileNotFoundException was raised.

编辑:当我从一个“不受信任”的网络共享拷贝dll时,我也有过这个问题。文件被Windows锁定,而FileNotFoundException被提高。

See here: Detected DLLs that are from the internet and "blocked" by CASPOL

参见这里:检测到来自互联网的dll和CASPOL的“阻塞”。

#2


2  

I resolved this problem by renaming the DLL. The DLL had been manually renamed when it was uploaded to its shared location (a version number was appended to the file name). Removing the version number from the downloaded file resolved the issue.

我通过重新命名DLL来解决这个问题。当它被上传到它的共享位置时,DLL就被手工重命名了(一个版本号被附加到文件名)。从下载的文件中删除版本号解决了这个问题。

#3


1  

I had the same issue. For me it helped to remove the .vs directory in the project folder.

我有同样的问题。对我来说,它有助于删除项目文件夹中的.vs目录。