Load a DLL and Its Dependencies
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 开发者_StackOverflow社区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.
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.
As a little more elegant version of your constructor idea you could use a splash screen to entertain the user at app start-up and simply make some arbitrary calls from your client code that force DLL loads. From a separate, non-ui thread...
Either with Assembly.Load or the force-load, the splash screen is a good idea.
Here's a decent-looking splash screen sample app from Code Project
Unless your application is going to use a specific type inside a referenced assembly from the late-loaded assembly there is no need to have the application itself load those references. Otherwise, Reed Copsey's answer would be your best bet.
精彩评论