title: TargetInvocationException on Activator.CreateInstance
body: <p>I'm having some trouble instantiating a class defined in a DLL file using Reflection. Even though the code seems fine I get TargetInvocationException on Activator.CreateInstance. The code goes as follows (for now only a single DLL is available):</p>
  
  <pre><code>public Comparator() 
  {
      string[] filePaths = Directory.GetFiles(@".\Extensions");
      for (int i = 0; i &lt; filePaths.Length; ++i)
      {
          var asm = Assembly.LoadFrom(Path.GetFullPath(filePaths[i]));
  
          if (asm != null)
          {
              foreach (Type currType in asm.ExportedTypes)
              {
                  if (!currType.IsAbstract &amp;&amp; currType.IsPublic &amp;&amp; typeof(SorterBase).IsAssignableFrom(currType))
                  {
                      Debug.WriteLine(currType); //outputs: BubbleSort.Sorter
                      var instance = Activator.CreateInstance(currType); //TargetInvocationException
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>This is the class I'm trying to instantiate:</p>
  
  <pre><code>using SortingLibrary;
  using SortingFunctions;
  namespace BubbleSort
  {
      public class Sorter : SorterBase //SorterBase is an abstract class defined in SortingLibrary
      {
          public Sorter()
          {
              SetFunction(Sorting.BubbleSort);
              AlgorithmName = @"Bubble Sort";
          }
      }
  }
  </code></pre>
  
  <p>The only way I managed to prevent that problem from happening was to add the loaded .dll to references before compilation. The problem is, that normally during compile time there is no way of telling what libraries will need to be loaded. What am I missing here?</p>
  
  <p>The entire solution (although a bit messy at the moment) can be downloaded here: <a href="http://nazr.in/rOD" rel="nofollow">http://nazr.in/rOD</a></p>
  
  <p>Any help will be really appreciated! Thank you in advance.</p>