title: Invoking remote methods is loading the remote assembly in parent appdomain
body: <p>I think I've determined that even though I'm loading assemblies in a MarshalByRefObject in a new AppDomain that the assemblies are also getting loaded into the parent domain.</p>
  
  <p>Here's my Assembly structure (arrows indicate dependency):</p>
  
  <pre><code>MainAssembly -&gt; CommonInterfaceAssembly &lt;- ExtensionAssembly
  </code></pre>
  
  <p>In the parent AppDomain I'm doing this:</p>
  
  <pre><code>var loader = (ExtensionLoader)extDomain.CreateInstanceAndUnwrap (Assembly.GetExecutingAssembly().FullName, "ExtensionLoader");
  loader.loadExtensions (this);
  </code></pre>
  
  <p>and the Loader class is:</p>
  
  <pre><code>class ExtensionLoader : MarshalByRefObject
  {
      public List&lt;IExtension&gt; loadExtensions (ExtensionMgr mgr)
      {
          // Delegate to Addins to return the list of extensions
          AddinManager.Initialize ();
          AddinManager.Registry.Update ();
          AddinManager.GetExtensionObjects&lt;IExtension&gt; ();
  
          var extensions = new List&lt;IExtension&gt; (AddinManager.GetExtensionObjects&lt;IExtension&gt; ());
          foreach (var ext in extensions) {
              ext.Initialize (mgr);
          }
          return extensions;
      }
  }
  </code></pre>
  
  <p>I don't know if it's relevant to the question, but I am using Mono.Addins to load the extensions in the new AppDomain so I've left that code in. From what I can tell though things work fine up to the point where I invoke the Initialize method on each of the extensions.</p>
  
  <p>So I have ran this scenario with the ExtensionAssembly in the same directory as the main executable and in a separate 'extensions' directory. What's curious to me is that when I invoke ext.Initialize either the ExtensionAssembly gets loaded in the parent AppDomain (if it exists in the same directory), or I get the below stack trace if not. Any ideas why?</p>
  
  <pre>
  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (System.Runtime.Remoting.Proxies.RealProxy rp, IMessage msg, System.Exception& exc, System.Object[]& out_args) [0x001f0] in /home/tim/tmp/mono-2.10.8/mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs:247 
  
  Exception rethrown at [1]: 
   ---> System.IO.FileNotFoundException: Could not load file or assembly 'Extensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
  File name: 'Extensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
    at System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, Boolean refonly) [0x00047] in /home/tim/tmp/mono-2.10.8/mcs/class/corlib/System/AppDomain.cs:785 
    at System.AppDomain.Load (System.String assemblyString) [0x00000] in /home/tim/tmp/mono-2.10.8/mcs/class/corlib/System/AppDomain.cs:762 
  </pre>