title: Calling Refresh() on a DirectoryCatalog throws ChangeRejectedException if new DLLs found in directory
body: <p>I'm experimenting with <a href="http://mef.codeplex.com" rel="nofollow noreferrer">MEF</a> and created a test program to call "plugins" that implement some given interface, which follows:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ProbeContract
  {
      public interface IProbe
      {
          int DoProbe(string what);
          List&lt;string&gt; GetCapabilities();
      }
  }
  </code></pre>
  
  <p>I created a sample console program which loads the "plugins" from its own assembly and, if any found, from a diretory in which one puts additional DLLs. The program works OK whether the plugins directory is empty (only the "native" plugins are called) or it has compatible DLLs to start with. BUT... if a new DLL is added between loop iterations, the Refresh() method of DirectoryCatalog throws a ChangeRejectedException, which is explained thusly:</p>
  
  <blockquote>
    <p>The composition remains unchanged. The
    changes were rejected because of the
    following error(s): The composition
    produced a single composition error.
    The root cause is provided below.
    Review the CompositionException.Errors
    property for more detailed
    information.</p>
    
    <p>1) Change in exports prevented by
    non-recomposable import
    'MEFTest.Program.ProberSet
    (ContractName="ProbeContract.IProbe")'
    on part 'MEFTest.Program'.</p>
  </blockquote>
  
  <p>The program is below, follow by the code for the DLL I try to add. What am I doing wrong?</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Reflection;
  using System.Collections;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using ProbeContract;
  using System.ComponentModel.Composition;
  using System.ComponentModel.Composition.Hosting;
  
  namespace MEFTest
  {
      class Program
      {
          [ImportMany]
          IEnumerable&lt;IProbe&gt; ProberSet { get; set; }
  
          CompositionContainer exportContainer;
          DirectoryCatalog pluginCatalog;
          AggregateCatalog catalog;
  
          private void Run()
          {
              catalog = new AggregateCatalog();
              catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
              string myExecName = Assembly.GetExecutingAssembly().Location;
              string myPath = Path.GetDirectoryName(myExecName);
              pluginCatalog = new DirectoryCatalog(myPath + "/Plugins");
              catalog.Catalogs.Add(pluginCatalog);
              exportContainer = new CompositionContainer(catalog);
  
              CompositionBatch compBatch = new CompositionBatch();
              compBatch.AddPart(this);
              compBatch.AddPart(catalog);
              exportContainer.Compose(compBatch);
  
              for (; ; )
              {
                  Console.Write("Press any key to run all probes: ");
                  Console.ReadKey(true);
                  Console.WriteLine();
                  pluginCatalog.Refresh();
                  foreach (var Prober in ProberSet)
                  {
                      Prober.DoProbe("gizmo");
                  }
              }
          }
  
          static void Main(string[] args)
          {
              Program p = new Program();
              p.Run();
          }
      }
  }
  </code></pre>
  
  <p>The plugin. The other two plugins are similar, the only difference being they reside in the same assembly as the main program:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.ComponentModel.Composition;
  using ProbeContract;
  
  namespace OtherProbes
  {
      [Export(typeof(IProbe))]
      public class SpankyNewProber : IProbe
      {
          public int DoProbe(string what)
          {
              Console.WriteLine("I'm Spanky and New and I'm probing [{0}]", what);
              return 0;
          }
  
          public List&lt;string&gt; GetCapabilities()
          {
              List&lt;string&gt; retVal = new List&lt;string&gt;();
              retVal.Add("spanky");
              retVal.Add("new");
              return retVal;
          }
      }
  }
  </code></pre>