Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load a DLL and Its Dependencies

Tags:

c#

.net

dll

How do I load a dll and its dependencies? I don't want to place each of the dependent dlls in an Assembly.Load. I'd rather just load the one dll and then the dependencies are loaded.

The above dlls aren't loaded when my application launches. They are only loaded when a user does a specific action, which then freezes the gui.

A workaround is to create an instance in my window's constructor and then set that instance to null. That definitely doesn't feel like the most elegant solution. Or is it? Thanks.

like image 219
kevindaub Avatar asked Oct 23 '25 03:10

kevindaub


1 Answers

You could load your assembly, then use:

var names = myAssembly.GetReferencedAssemblies();

Assembly.GetReferencedAssemblies will give you the full list of assemblies referenced by your assembly. Just load those, as well, and you'll have loaded all of your dependencies.

like image 196
Reed Copsey Avatar answered Oct 25 '25 18:10

Reed Copsey



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!