title: Instantiate all classes implementing a specific interface
body: <p>I have an interface <code>IExample</code>, and a set of classes <code>ClassOne</code>, <code>ClassTwo</code> and <code>ClassThree</code>, all defined in different namespaces. I will possibly remove either of the classes, or add a new one in a new place, at a later stage in development.</p>
  
  <p>Now, I want to <strong>find all types that implement <code>IExample</code> at runtime, and instantiate them</strong>. (I know on beforehand that no class implementing <code>IExample</code> will ever need any constructor arguments, but I don't know how to specify that in code, so it's me - not the compiler - that knows...)</p>
  
  <p>Is this possible? How do I go about to do it?</p>
  
  <p><strong>Update:</strong> I've now tried several of the approaches suggested, but on all of them, the line <code>Activator.CreateInstance(type)</code>, I get a System.MissingMethodException because I "cannot create an instance of an interface." This is my code:</p>
  
  <pre><code>var tasks = AppDomain.CurrentDomain.GetAssemblies()
      .SelectMany(a =&gt; a.GetTypes())
      .Where(t =&gt; typeof(IBootstrapperTask).IsAssignableFrom(t))
  
      // This line is where it fails
      .Select(t =&gt; Activator.CreateInstance(t) as IBootstrapperTask)
  
      .ToArray();
  new AutoMapperBootstrapper(tasks).Initialize();
  </code></pre>
  
  <p>Without the <code>as</code> clause I don't see any exception, but I'm given an <code>object[]</code>, and I need an <code>IBootstrapperTask[]</code> for the constructor on the last line in the excerpt. I've tried various ways to cast it, but none seem to work.</p>