C# Plugins and event handlers
<p>I'm trying to write some kind of plugin framework... The problem is:
I want to use methods from plugins as event handlers for controls in the host application and prevent loading plugin assembly into the main appdomain. The following code causes plugin.dll to be loaded into the main appdomain =( Is there any other way to do that?</p>

<p>Host application:</p>

<pre><code>public partial class Form1 : Form
{
    private AssemblyLoader _aLoader = null;

    public Form1()
    {
        InitializeComponent();

        AppDomain _domain = AppDomain.CreateDomain("Remote Load");
        _aLoader = (AssemblyLoader)_domain.CreateInstanceAndUnwrap(
                                 "Loader", "Loader.AssemblyLoader");

        _aLoader.Load();

        EventHandler eh = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), _aLoader.Instance, _aLoader.Method);

        button1.Click += eh;
    }
}
</code></pre>

<p>AssemblyLoader:</p>

<pre><code>[Serializable]
public class AssemblyLoader : MarshalByRefObject
{
    object _instance = null;
    MethodInfo _method = null;

    public void Load()
    {
        Assembly _assembly = Assembly.LoadFile(Environment.CurrentDirectory + @"\Plugin.dll");
        Type _type = _assembly.GetType("Plugin.Test");
        _instance = Activator.CreateInstance(_type);
        _method = _instance.GetType().GetMethod("TestEventHandler");
    }

    public MethodInfo Method
    {
        get { return _method; }
    }

    public object Instance
    {
        get { return _instance; }
    }
}
</code></pre>

<p>Plugin:</p>

<pre><code>[Serializable]
public class Test
{
    public void TestEventHandler(object sender, System.EventArgs e)
    {
        MessageBox.Show("Pingback from plugin");
    }      
}
</code></pre>
