I keep getting this error on the following code when I attempt to load my plugins from the Plugins folder. If I move my plugins out of the Plugin folder and into the Application.StartupPath, the problem disappears. In other words, if I try to load the plugins from c:\utils\C#\WinZm\bin\Debug\Plugins, the app generates the error. But if I load them from c:\utils\C#\WinZm\Bin\Debug (the ApplicationStartupPath) the plugins load without any problem. Any suggestions for a resolution?
Attachment 7096
Code:private void Form1_Load(object sender, System.EventArgs e)
{
string path = Application.StartupPath + @"\Plugins";
//string path = "C:\\utils\\C#\\WinZM\\bin\\Debug";
MessageBox.Show(path);
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
{
// load it
Assembly ass = null;
ass = Assembly.Load(args);
if (ass != null)
{
ObjType = ass.GetType(args + ".PlugIn");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
try
{
// Create the object as we have the Report Type
if (ObjType != null)
{
ipi[i] = (IPlugin)Activator.CreateInstance(ObjType);
ipi[i].Host = this;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}