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 开发者_如何学Pythonthought 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
andclipper.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 referencedclipper.dll
- all also on the same problem machine. After several hours of regasm hell I was able to further isolate it to this.
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.
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
Make sure to include the C++ runtime Libraries (CRT) on your client machine.
Well , there may be lot of reasons
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.
is the COM object (foo.dll) registered on the troubled computer?
Please remove pdbs from the installation folder also.
Are your application files downloaded from the internet? I once had the same problem where my program was downloaded in a zip file, and then extracted on the client machine. Once extracted I was getting exactly the same error message "The specified module could not b e found."
It turned out to be Windows security policy for files downloaded from the internet. Windows will "block" downloaded files, and they need to be unblocked manually. In my case, I needed to right click on the file, select properties and then select "unblock", my application was then able to load the assembly as normal.
http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=mpe&DownloadId=163767
Alternatively you can unblock the zip file before extracting it, and then all extracted files will also be unblocked.
精彩评论