Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't my application find a dependent dll in the same directory?

I have a simple console test application, ConsoleApplication1.exe, which references another assembly clipper.dll.

On 3 machines that I've tested it on, it is possible to place both files in e.g. c:\test\, and execute ConsoleApplication1.exe.

On one other machine, which happens to be a client machine, running ConsoleApplication1.exe results in a program crash and the following being printed to the console:

C:\test>dir
 Volume in drive C has no label.
 Volume Serial Number is 7C46-414F

 Directory of C:\test

07/12/2010  06:08 PM    <DIR>          .
07/12/2010  06:08 PM    <DIR>          ..
07/12/2010  05:13 PM            11,776 ClassLibrary1.dll
07/12/2010  05:13 PM            30,208 ClassLibrary1.pdb
07/12/2010  04:55 PM             3,572 ClassLibrary1.tlb
19/11/2010  02:46 PM           235,008 clipper.dll
19/11/2010  02:46 PM         1,534,976 clipper.pdb
07/12/2010  05:13 PM             6,144 ConsoleApplication1.exe
07/12/2010  05:13 PM            11,776 ConsoleApplication1.pdb
01/08/2010  12:52 PM           139,264 nunit.core.dll
01/08/2010  06:41 AM            57,344 nunit.core.interfaces.dll
01/08/2010  06:41 AM           135,168 nunit.framework.dll
01/08/2010  06:41 AM           547,262 nunit.framework.xml
              11 File(s)      2,712,498 bytes
               2 Dir(s)  477,821,784,064 bytes free

C:\test>ConsoleApplication1.exe

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'clipper.dll' or one of its dependencies. The specified module could not b
e found.
   at ConsoleApplication1.Program.Main(String[] args)

This is a odd to me, although I don't understand dll load rules comprehensively I thought it would search the CWD for the specified file. And the fact this same setup works on the various other computers I've tried is also odd.

Curiously, on a working computer if I remove clipper.dll and then run it:

C:\Temp>ConsoleApplication1.exe

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass
embly 'clipper, Version=1.0.3975.26584, Culture=neutral, PublicKeyToken=null' or
 one of its dependencies. The system cannot find the file specified.
   at ConsoleApplication1.Program.Main(String[] args)

The unhandled exception is slightly different, with a full assembly name.

  • Both ConsoleApplication1.exe and clipper.dll are built for .NET 4.
  • All machines have the .NET 4 runtime installed. The problem machine does not have the .NET sdk
  • clipper.dll is a combination of ummanaged c++ code and C++/CLI. It is a suspicious character because it is basically the first C++/CLI .NET assembly I have created and much fumbling was involved. It seems to load in reflector fine.
  • These efforts came about when I was trying to figure out why I was unable to successfully utilise a COM object (call it foo.dll) which also referenced clipper.dll - all also on the same problem machine. After several hours of regasm hell I was able to further isolate it to this.
like image 464
fostandy Avatar asked Dec 07 '10 08:12

fostandy


People also ask

How do I add a dependency to a DLL?

To do this, go to Project Properties->Configuration Properties->Linker->Input and look for Additional dependencies. If you put the name of the . lib file (including the extension) here then it will try to link with it.

Can't find dll file?

If DLL files are missing on your Windows 11/10/8/7 computer, the best ways to fix such errors are as follows: Run the built-in System File Checker tool to replace missing or corrupted operating system files. Run the DISM tool and repair the Windows system image and fix a corrupted Windows Component Store.

How do I find the location of a DLL?

Your DLL files are located in C:\Windows\System32. When Windows Defender runs a Full Scan, it includes that directory and so all of your DLLs will be scanned. This will scan your DLL files for any malware infections.

What is DLL dependency?

The use of DLLs helps promote modularization of code, code reuse, efficient memory usage, and reduced disk space. So, the operating system and the programs load faster, run faster, and take less disk space on the computer. When a program uses a DLL, an issue that is called dependency may cause the program not to run.


2 Answers

or one of its dependencies

Did you deploy the CRT runtime DLLs on that machine? Make sure to deploy the Release build of your assembly. The debug version of the CRT is not redistributable.

like image 70
Hans Passant Avatar answered Oct 16 '22 12:10

Hans Passant


I don't know why it happed to u, but if you will copy the dll to system32 directory it will lead to 2 option 1) It will work 2) It won't work and that way you will know it doesn't relate to the dll path

like image 44
Delashmate Avatar answered Oct 16 '22 13:10

Delashmate