2
votes

I am trying to build a .NET client software package that downloads its components on demand.

Let's say I have a program that is split into a main executable and 20 other dll files. The main program references 3 of them, they reference some others, anyway... they have some kind of tree like dependency structure.

The thing I am trying to achieve is to distribute just the main executable and get everything else from a server location on-demand.

Something like this: The main program and all these dll projects are in a single solution and are built together just like any other solution. While distributing, only the exe is distributed, the other dll's (including some third party libraries used) are put in a server location available for download.

The exe runs, shows some UI, when the user clicks a menu item, another UI window from one the dll files is to be shown so the OS looks for the dll (which is not there), I intervene, download the required dll from the server, put it next to the exe and let the OS load it as if it was there from the very beginning.

This looks achievable by the use of a common Interface class and some reflection magic but I was hoping for something more, something that includes building the dll's altogether in a single solution, something that includes the on-demand download of 3rd party libraries.

Any ideas how to do this?

3
You are asking for a lot of trouble. The security and versioning problems this can cause are hard to deal with.Hans Passant
I am well aware of this but it is a risk I need to take. The problem I described above is only the point I was stuck on. It is part of a much larger picture.e-mre

3 Answers

1
votes

You're looking for the AppDomain.AssemblyResolve event, which allows you to load assemblies from custom locations.
You won't need any other reflection.

1
votes

Provide event handlers for AppDomain.ResolveAssembly and AppDomain.ResolveType events for your current appdomain and load the assemblies.

But be careful to load the assemblies into the right context: http://msdn.microsoft.com/en-us/library/dd153782.aspx

1
votes

You can cath the AssemblyResolve event, that fires when an assembly is not found, and then download the assembly it tries to find.

You should read this article.