title: AppDomain shadow copying not working (original assemblies locked)
body: <p>Here's a small class I'm using to probe for a list of available plugins:</p>
  
  <pre><code>internal static class PluginDirectoryLoader
  {
      public static PluginInfo[] ListPlugins(string path)
      {
          var name = Path.GetFileName(path);
          var setup = new AppDomainSetup
          {
              ApplicationBase = path,
              ShadowCopyFiles = "true"
          };
          var appdomain = AppDomain.CreateDomain("PluginDirectoryLoader." + name, null, setup);
          var exts = (IServerExtensionDiscovery)appdomain.CreateInstanceAndUnwrap("ServerX.Common", "ServerX.Common.ServerExtensionDiscovery");
          PluginInfo[] plugins = null;
          try
          {
              plugins = exts.ListPlugins(); // &lt;-- BREAK HERE
          }
          catch
          {
              // to do
          }
          finally
          {
              AppDomain.Unload(appdomain);
          }
          return plugins ?? new PluginInfo[0];
      }
  }
  </code></pre>
  
  <p>The <code>path</code> parameter points to a subdirectory containing the plugin assemblies to load. The idea is to load them using a separate AppDomain with shadow copying enabled.</p>
  
  <p>In <em>this</em> case, shadow copying isn't really necessary seeing as the AppDomain is unloaded quickly, but when I actually load the plugins in the next block of code I intend to write, I want to use shadow copying so the binaries can be updated on the fly. I have enabled shadow copying in this class as a test to make sure I'm doing it right.</p>
  
  <p>Apparently I'm not doing it right because when I break in the debugger on the commented line in the code sample (i.e. <code>plugins = exts.ListPlugins()</code>), the original plugin assemblies are locked by the application!</p>
  
  <p>Seeing as I'm specifying that assemblies loaded by the AppDomain should be shadow copied, why are they being locked by the application?</p>