<p>I'd like to provide some way of creating dynamically loadable plugins in my software.
Typical way to do this is using the <a href="http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx" rel="noreferrer">LoadLibrary</a> WinAPI function to load a dll and calling <a href="http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx" rel="noreferrer">GetProcAddress</a> to get an pointer to a function inside that dll.</p>

<p>My question is how do I dynamically load a plugin in C#/.Net application?</p>

The following code snippet (C#) constructs an instance of any concrete classes derived from
```
Base
```
found in class libraries (*.dll) in the application path and stores them in a list.
```
```
using System.IO;
using System.Reflection;

List<Base> objects = new List<Base>();
DirectoryInfo dir = new DirectoryInfo(Application.StartupPath);

foreach (FileInfo file in dir.GetFiles("*.dll"))
{
    Assembly assembly = Assembly.LoadFrom(file.FullName);
    foreach (Type type in assembly.GetTypes())
    {
        if (type.IsSubclassOf(typeof(Base)) && type.IsAbstract == false)
        {
            Base b = type.InvokeMember(null,
                                       BindingFlags.CreateInstance,
                                       null, null, null) as Base;
            objects.Add(b);
        }
    }
}
```
```
Edit:
The classes referred to by
Matt
are probably a better option in .NET 3.5.