title: Activator.CreateInstance with dynamic Type
body: <p>I think I have a lack of understand, what exactly is happening:
  The user can enter a Path to an Assembly and an Object type and I try to create a instance of it.</p>
  
  <p>My approach:</p>
  
  <pre><code>        Assembly a = Assembly.LoadFile(txtAssemblyPath.Text);
          Type myType = a.GetTypes().ToList().FirstOrDefault(f =&gt; f.Name == txtObjectName.Text);
  
          var obj = Activator.CreateInstance&lt;myType&gt;();
          var obj2 =(myType) Activator.CreateInstance(myType);
  </code></pre>
  
  <p>The problem is in the Creation of the Object itself. It seems like the myType is not threated as a Type. On this example: <a href="https://stackoverflow.com/questions/10708925/creating-generic-variables-from-a-type-how-or-use-activator-createinstance">Creating generic variables from a type - How? Or use Activator.CreateInstance() with properties { } instead of parameters ( )?</a> </p>
  
  <p>They just get an object, so I guess this is not the same Case. What I dont understand at all: CreateInstance(Type) works, but CreateInstance with the Type doesn't, but T and Type should be the same: System.Type.</p>
  
  <p>Thanks in advance for clarifying.</p>
  
  <p>Matthias</p>