title: C# Compile in memory and create instance of memory assembly types
body: <p>How can I Load an assembly to memory and instatiate one of its types by using their name?</p>
  
  <p>I have this to compile:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Compiles the input string and saves it in memory
      /// &lt;/summary&gt;
      /// &lt;param name="source"&gt;&lt;/param&gt;
      /// &lt;param name="referencedAssemblies"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static CompilerResults LoadScriptsToMemory(string source, List&lt;string&gt; referencedAssemblies)
      {
          CompilerParameters parameters = new CompilerParameters();
  
          parameters.GenerateInMemory = true;
          parameters.GenerateExecutable = false;
          parameters.IncludeDebugInformation = false;
  
          //Add the required assemblies
          foreach (string reference in referencedAssemblies)
              parameters.ReferencedAssemblies.Add(reference);
  
          foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
          {
              if (asm.Location.Contains("Microsoft.Xna") || asm.Location.Contains("Gibbo.Library") 
                  || asm.Location.Contains("System"))
              {
                  parameters.ReferencedAssemblies.Add(asm.Location);
              }
          }
  
          return Compile(parameters, source);
      }
  
      /// &lt;summary&gt;
      /// Compiles a source file with the given parameters and source
      /// &lt;/summary&gt;
      /// &lt;param name="parms"&gt;&lt;/param&gt;
      /// &lt;param name="source"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      private static CompilerResults Compile(CompilerParameters parameters, string source)
      {
          CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp");
          return compiler.CompileAssemblyFromSource(parameters, source);
      }
  </code></pre>
  
  <p>Then, I try to use this to instantiate on of the members generated in memory by the code above:</p>
  
  <pre><code>    var handler = Activator.CreateInstance(SceneManager.ScriptsAssembly.FullName, name);
      ObjectComponent oc = (ObjectComponent)handler.Unwrap();
  </code></pre>
  
  <p>SceneManager.ScriptsAssembly.FullName :> I save the compiled assembly in SceneManager.ScriptsAssembly.</p>
  
  <p>name :> name of the type I want to load</p>
  
  <p>I got this error:</p>
  
  <blockquote>
    <p>Error loading scene: Could not load file or assembly 'nhvneezw, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.</p>
  </blockquote>
  
  <p>The assembly name is correct. What may it be?</p>
  
  <p>Thanks in advance.</p>