System.IO.FileNotFoundException: Could not load file or assembly 'X' or one of its dependencies when deploying the application
Asked Answered
M

6

61

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

I've created an assembly X, compiled it and referenced it in an exe file, called 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.

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?

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.

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

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

*** 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

Maitland answered 4/6, 2012 at 8:47 Comment(2)
Please see my updated answer and check if your dlls are blocked because they are from an untrustworthy source.Hoban
Sounds like something you should investigate using the Fusion Log - #4563359Staffman
H
33

... Could not load file or assembly 'X' or one of its dependencies ...

Most likely it fails to load another dependency.

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

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

Also check your build configuration (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.

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

Hoban answered 4/6, 2012 at 8:50 Comment(2)
@ArsenZahray So how did you resolve the issue? I am facing a similar issue. System.IO.FileNotFoundException: Could not load file or assembly 'Logging, Version=7.7.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.Hermanhermann
@vaibhav: You can attach to the Assembly.Resolve event to find out which assembly is missing: learn.microsoft.com/de-de/dotnet/api/…Hoban
T
7

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

Teague answered 15/6, 2017 at 13:23 Comment(2)
That didn't help in my case.Unmoral
since the exception occurs only when binary files are deployed, there is no .vs folder to remove unfortunatelyIntervention
L
6

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.

Lovett answered 13/1, 2016 at 11:50 Comment(0)
N
2

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

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

Press ENTER to change working directory

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

Press ENTER

Nonaggression answered 31/1, 2020 at 19:16 Comment(0)
C
1

For me, I started the app from within windows explorer (by double clicking on it). Then it crashed immediately.

I then opened Event Viewer of windows and viewed Application and it displayed full stacktrace of error. The stacktrace showed relation with Bitmap or images. It was then turned out to be due to app icon not found

Criseldacrisey answered 7/12, 2020 at 13:31 Comment(0)
A
1

Sometimes even Process Monitor won't show you the DLL and where it's looking.

Take this scenario, the Orange is Library Reference A, it's a project reference.

Next is the Yellow which is Library Reference B that also has a ref to Library Reference A. Now here's the catch, see how the Green arrow indicates LibA is a project ref, there's no expand/collapse to see its sub-references.

But yet when I expand Library B I can see that I can expand Library Reference A! When I do that I see it's an old version, potentially a nuget one. This is the problem for my scenario, the references have to use the same version DLL or simply all use a Project Reference.

enter image description here

Arundel answered 18/4, 2023 at 2:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.