System.IO error?!?!?

  • Thread starter Thread starter k7s41gx
  • Start date Start date
K

k7s41gx

Guest
Hey all,


I have some code that I am working on which allows a user to load and unload assemblies/plugins while the application is running. Now the loading code works as long as its under the main form. When I move the code to a seperate class I get this error, "System.IO.FileLoadException: 'Could not load file or assembly 'Plugins\\TestPlugin' or one of its dependencies. The given assembly name or codebase was invalid." Now I know the plugin is in there because I can load it manually using a different command. I will post both methods below.


Separate Class Code (DOES NOT WORK - PLEASE HELP) IT STOPS ON THE INSTANCE UNWRAP.

public void LoadPlugins()
{
if (Directory.Exists(Constants.FolderName))
{
string[] files = Directory.GetFiles(Constants.FolderName);
foreach (string file in files)
{
if (file.EndsWith(".dll"))
{
string cow = file;
string[] beat = cow.Split(new char[] { '.' });
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
domaininfo.ApplicationName = beat[0];
domaininfo.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\";
//Evidence field below is the NULL.
var domain = AppDomain.CreateDomain(beat[0], null, domaininfo);
KPlugin child = domain.CreateInstanceAndUnwrap(beat[0], beat[0] + ".Plug") as KPlugin;
pluginhandler.Plugins.Add(child);
child.Initialize(new DomainHost());
}
}
}
}

Working code on separate command inside main form. What am I doing wrong? These are identical.

if (input[0] == "/run")
{
try
{
textBox1.Text = null;
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
domaininfo.ApplicationName = input[1];
domaininfo.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\";
//Evidence field below is the NULL.
var domain = AppDomain.CreateDomain(input[1], null, domaininfo);
KPlugin child = domain.CreateInstanceAndUnwrap(input[1], input[1] + ".Plug") as KPlugin;
//Child = input[1].Plug. Note this for future reference.
pluginhandler.Plugins.Add(child);
child.Initialize(new DomainHost());
child.Go(input[2]);
//AppDomain.Unload(domain);
}
catch (Exception r)
{
output.AppendText(Environment.NewLine);
output.AppendText("Error trying to load plugin: " + r);
output.ScrollToCaret();
foreach (string s in input)
{
output.AppendText(Environment.NewLine);
output.AppendText("STRING LOADER: " + s);
output.ScrollToCaret();
}
}
}

Continue reading...
 
Back
Top