Ahh, found it!!! The problem is that the Load method uses the Framework discovery rules. I.e., the Global Assembly Cache (GAC), the path in the app's manifest, the directory where your app resides etc. If the plugin is outside of the discovery rules, as in my case where it was located below the app's directory, it will not load. The solution is to use the LoadFile method which will always load the path requested.
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
string args1;
string path = Application.StartupPath + @"\Plugins\";
string[] pluginFiles = Directory.GetFiles(path, "*.dll");
ipi = new IPlugin[pluginFiles.Length];
for (int i = 0; i < pluginFiles.Length; i++)
{
string args = pluginFiles[i].Substring(
pluginFiles[i].LastIndexOf("\\") + 1,
pluginFiles[i].IndexOf(".dll") -
pluginFiles[i].LastIndexOf("\\") - 1);
Type ObjType = null;
try
{
Assembly asm;
args1 = path + args + ".dll";
asm = Assembly.LoadFile(args1);
Type[] types = asm.GetTypes();
if (asm != null)
{
ObjType = asm.GetType(args + ".PlugIn");
ipi[i] = (IPlugin)Activator.CreateInstance(ObjType);
ipi[i].Host = this;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}