Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# load DLL from different folder?

I have a C# project that contains 1 EXE and about 7 DLLs. What I would like to have is a folder beside the EXE called "Library" (or something similar) that contains all the DLLs so that it is a bit more organized and looks better for the end user.

I know this can be done using an AppConfig but the I don't want another file beside the EXE. All I want is the main EXE and the folder.

Is it possible to use AppConfig and embed it or load the DLLs without using a AppConfig that won't change how I currently use my DLLs? I know you can load a DLL at run time but I don't think that is what I am looking for.

Thanks!

EDIT

I know the pros and cons to doing this, so please only answers on how to do this and no advice as to why I should or should not do this.

like image 843
Landin Martens Avatar asked Jul 01 '26 04:07

Landin Martens


2 Answers

Use System.Reflection.Assembly.LoadFrom(path).

LoadFrom will allow it to look in the same folder as the targetted dll for any dependencies. If you use Load, then it will not consider dlls that are sitting in the same folder as the dll you Load.

I know this doesn't directly answer your question, but manually calling LoadFrom on the DLLs early in your process startup should do the trick if you want an "xcopy" installable .net app or something.

like image 200
doug65536 Avatar answered Jul 03 '26 19:07

doug65536


PrettyBin is your solution. It does this beautifully!

like image 27
Aneesh Vijendran Avatar answered Jul 03 '26 19:07

Aneesh Vijendran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!