title: CompilerParameters.GenerateInMemory
body: <p>Hi i want to compile a class at runtime using CodeDom and generate in memory. How do i go about running the compiled code from memory?</p>
  
  <p>My TextFile Resource:</p>
  
  <pre><code>using System.IO;
  using System;
  
  namespace Exe_From_Memory
  {
      static class MemoryExe
      {
          static void Main()
          {
              string strText = "[TEXT]";
              Console.WriteLine(strText);
              Console.Read();
          }
      }
  }
  </code></pre>
  
  <p>My actual application which compiles the textfile</p>
  
  <pre><code>private void exeButton_Click(object sender, EventArgs e)
  {
      string text = textBox1.Text;
      string source;
  
      source = Properties.Resources.MemoryExe;
      source = source.Replace("[TEXT]", text);
  
      CompilerParameters _CompilerParameters = new CompilerParameters();
  
      _CompilerParameters.ReferencedAssemblies.Add("System.dll");
      _CompilerParameters.GenerateExecutable = true;
      _CompilerParameters.GenerateInMemory = true;
  
      _CompilerParameters.IncludeDebugInformation = false ;
  
      CSharpCodeProvider _CSharpCodeProvider = new CSharpCodeProvider();
      CompilerResults _CompilerResults = _CSharpCodeProvider.CompileAssemblyFromSource(_CompilerParameters, source);
  
      Assembly _Assembly = _CompilerResults.CompiledAssembly;
      MethodInfo mi = _Assembly.EntryPoint;
      object o = _Assembly.CreateInstance(mi.Name);
      mi.Invoke( o, null);
  
      foreach (CompilerError _CompilerError in _CompilerResults.Errors)
      {
          MessageBox.Show(_CompilerError.ToString());
      }
  }
  </code></pre>
  
  <p>The debugger simply says:
  'Exe From Memory.vshost.exe' (Managed): <strong>Loaded 'r8ztr3t0'</strong>
  Since its loaded why doesnt the console window show?</p>