D
David Elliott
I am trying to load an assembly and execute a method from a class.
I have listed 3 parts to the code.
1) The Driver to load and execute
2) The Interface
3) The assembly
I have a valid referece to the assembly. When I try to create an instance
of the class, it returns a null value.
Any help would be appreciated.
As a side note, if someone created their own IPlugIn and was wanting to use
it in my application, Is there a way to acertain their class which is equivalent
to my MainEntry? At the time that they create their assembly, they wouldn't
necessarily know to name their class MainEntry.
Thanks,
Dave
(e-mail address removed)
===================================================
IPlugIn plugin = null;
Assembly assembly = null;
assembly = Assembly.LoadFrom(assemblyName);
plugin = (IPlugIn)assembly.CreateInstance("IPlugIn.MainEntry");
===================================================
namespace Plugin
{
/// <summary>
/// Summary description for IPlugIn.
/// </summary>
public interface IPlugIn
{
string PluginName{get;}
void ExecutePlugin();
}
}
===================================================
public class MainEntry : IPlugIn
{
private int m_pluginID = 1;
private string m_pluginName = "Plugin #1";
public string PluginName {get {return m_pluginName;}}
public int PluginID {get {return m_pluginID;} set {m_pluginID = value;}}
public void ExecutePlugin()
{
MessageBox.Show("ExecutePlugin has executed", "ExecutePlugin()");
}
}
===================================================
I have listed 3 parts to the code.
1) The Driver to load and execute
2) The Interface
3) The assembly
I have a valid referece to the assembly. When I try to create an instance
of the class, it returns a null value.
Any help would be appreciated.
As a side note, if someone created their own IPlugIn and was wanting to use
it in my application, Is there a way to acertain their class which is equivalent
to my MainEntry? At the time that they create their assembly, they wouldn't
necessarily know to name their class MainEntry.
Thanks,
Dave
(e-mail address removed)
===================================================
IPlugIn plugin = null;
Assembly assembly = null;
assembly = Assembly.LoadFrom(assemblyName);
plugin = (IPlugIn)assembly.CreateInstance("IPlugIn.MainEntry");
===================================================
namespace Plugin
{
/// <summary>
/// Summary description for IPlugIn.
/// </summary>
public interface IPlugIn
{
string PluginName{get;}
void ExecutePlugin();
}
}
===================================================
public class MainEntry : IPlugIn
{
private int m_pluginID = 1;
private string m_pluginName = "Plugin #1";
public string PluginName {get {return m_pluginName;}}
public int PluginID {get {return m_pluginID;} set {m_pluginID = value;}}
public void ExecutePlugin()
{
MessageBox.Show("ExecutePlugin has executed", "ExecutePlugin()");
}
}
===================================================