简体   繁体   中英

c# app can't find dll in its working directory

I just switched from C++ to C# and I am a bit confused about referencing DLLs.

I have a third party DLL and a simple testing application that uses some of its methods. When I compile the project, everything goes well, but when I run the compiled app on another computer, I've got an error that says that the DLL is missing even though the DLL is in the app's working directory. What's even more strange is that I have access to the source code of another app that is dependent on an older version of this DLL and this app works well.

I've gone through the code and all the solution settings without finding anything really different.

Can you tell me how to reference a .dll from a working dir (Visual Studio 2010)?


Below is the exception:

System.IO.FileNotFoundException was unhandled

Message=Could not load file or assembly 'TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928' or one of its dependencies. The system cannot find the file specified.

Source=ICtestapp

FileName=TIS.Imaging.ICImagingControl32, Version=3.2.4.1146, Culture=neutral, PublicKeyToken=257805929e8b7928

FusionLog=WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 StackTrace:
      at ICtestapp.Form1.InitializeComponent()
      at ICtestapp.Form1..ctor()
      at ICtestapp.Program.Main()
 InnerException: 

Here's a good blog post from Suzanne Cook from the .net team on debugging .net loader issues.

http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx

and here's the details on how it loads:

http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.71).aspx

You have to add the dll as reference in your project references, once you added the library in the reference, when you compile the program the dll will be automatically copied to the compilation output folder unless otherwise specified in the reference properties ...

Then if you copy all items that you will find in the compilation output folder in the new location in the other PC, you should not have any problems.

Check also that the .NET framework installed on the other machine is at least as the same level of the project target ..

This also happens when you copy the debug executables over to another machine. Try compiling in release and moving over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM