title: Activator.CreateInstance() specific class type instance
body: <p>this question is an addition to <a href="https://stackoverflow.com/questions/15451697/get-a-class-without-a-lot-of-if-statements">this</a> previously asked question.</p>
  
  <p><strong>My child classes which should be initialised and the base class which will be the list type</strong></p>
  
  <pre><code>abstract public class baseClass
  {
      public baseClass()
      {
      }
  }
  
  public class child1 : baseClass
  {
      public child1() : base
      {
      }
  }
  
  public class child2 : baseClass
  {
      public child2() : base
      {
      }
  }
  </code></pre>
  
  <p><strong>My enum and manager class</strong></p>
  
  <pre><code>public enum ClassType
  {
      child1,
      child2
  }
  
  public class Manager
  {
      private List&lt;baseClass&gt; _children;
  
      public void Initialise(ClassType type)
      {
          var temp = Activator.CreateInstance(null, type.ToString()); 
          //null = assembly which means this assembly
          _children.Add(temp);
      }
  }
  </code></pre>
  
  <p>The manager class has been updated into the suggested answer from my previous question. However something is still wrong.
  In the case above I get the error:
  TypeLoadException was unhandled: Could not load type 'child2' from assembly 'Something'
  how can I change this?
  I did try some other options without success. (some resulting in a creation of the class but when adding resulting in a nullReferenceException).</p>
  
  <p><strong>EDIT :</strong></p>
  
  <p>Okay I changed my code into:</p>
  
  <pre><code>string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
  Type objType = Type.GetType(string.Format("{0}.{1},{0}", assemblyName, type.ToString()));
  var temp = (baseClass)Activator.CreateInstance(objType, 1);
  // 1 is the parameter I need to add to the constructor.
  _children.Add(temp);
  </code></pre>
  
  <p>now I get the correct class created, but I get a NullReferenceException when I add the class to the list :(</p>