Creating a plugin architecture in .net is pretty easy. Unless you need to unload the plugins - AppDomain.Unload just does not work. Unfortunately I have found little help on this issue ~ google ~ so I decided to write this article.
A few basics:
1. .net uses application domains - kind of VM isolation in Java
2. multiple app domains can exist into a single process
3. code running in on app domain cannot directly access code/resources in another app domain - they are isolated.
4. code failures in one app domain cannot affect other app domains
5 . individual assemblies cannot be unloaded, only whole app domains
In our case we will use a process containing a main domain - the main application - and another one where to load/unload plugins. It should look like this:
The main domain contains standard assemblies - mscorlib, System, etc - plus our plugins.dll module - this is the main application.
We now create another app domain in our code using:
AppDomain appDomainPluginA = AppDomain.CreateDomain("appDomainPluginA");
The domains should look like this: