Jump to content
  • Advertisement
Sign in to follow this  
shrek2

[.net] Why are dlls in same folder as executable?

This topic is 3778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I build a windows application using Microsoft Visual C# Express. I added a reference (dll) to my project. In the bin/release/ folder, I see my executable along with the dll. I originally added the dll from another folder. Looks like C# made a copy and put it in the bin/release/ folder. If I take the executable out of the folder and try to run it, I get an error message saying that it cannot find the dll. How can I fix this? I don't want to always move the two files together, especially if I need to run the executable on another computer. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Another option is to put it in your system32 directory. I am not sure how or if you can specify other directories to search for the DLL.

Share this post


Link to post
Share on other sites
Right click on the reference in Solution Explorer under References, and it should have Copy Local or something like that set to true. That's why it's copied. The reason your program doesn't run without it is because it doesn't know where to find it otherwise. If you want your program to run, you will need to move the files around together.

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
You could try using ILMerge to merge multiple assemblies into a single file.
Yeah, uh...I've heard nothing but horror stories from anyone who has ever tried to seriously do that.

Share this post


Link to post
Share on other sites
There are much ways to load dlls in .Net. If you want to place them in another folder, then you can use AppDomain.Current.Load(...).
By looking to the different overloads of this you will recognize that you can load a dll from a byte array. That gives you much flexebility. You can even Attach your dll as a resource in you main dll and load it from there.

There are also some other ways, but i think, that should be what you want. But be carefull, you have to execute this call before any call to a type / method of that assembly.

Share this post


Link to post
Share on other sites
i originally loaded the dll from a specific folder in my computer. i added it by using the references menu. in the destination computer, the dll will be as the same folder. the destination computer will always have the dll.

in this case, what is the best way to solve my problem? can you tell me exactly what i need to do so that i only need to distribute the exe file? thanks.

Share this post


Link to post
Share on other sites
if you are 100% that the destination PC will have the dll, all you need to do for redistribution is send them the exe file.

The reason for the copy is that the dll isn't in a system path, and so cant be found when VS tries to run the program, hence it copies the dll to the running directory of your app.

i dont see why this is a problem for you though, if you want to be safe just redistribute both the exe and the dll.

Share this post


Link to post
Share on other sites
how can i specify the directory path of the dll? the path property of the dll in reference menu does have the correct path, but it's greyed out. if i change the "copy local" property to false, then i can't build the program. the error message says that it cannot find the dll.

say i want the exe to always look for the dll in this folder

c:\widget
how do i do this?

Share this post


Link to post
Share on other sites
Amazing. I am just studing this, and I also wanted to post this today.
A solution can be:
SetDllDirectory
http://msdn.microsoft.com/en-us/library/ms686203(VS.85).aspx

I don't know i it works in .net, i doesn't work for me because I think I have an outdated windows unit (working in Delphi here).
Try to get your compiler to set the library path to the *.DLL location.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!