title: .Net assemblies not working in PowerShell 2 runspaces
body: <p>I'm running powershell scripts from c# by way of <code>Runspace</code> and <code>Pipeline</code>.</p>
  
  <p>I need to support Powershell 2</p>
  
  <p>My script uses <code>[System.Net.WebRequest]</code></p>
  
  <p>From the PS CLI on this machine, <code>[System.Net.WebRequest]</code> works fine.</p>
  
  <p>However, running a script from c# results in </p>
  
  <pre><code>Unable to find type [System.Net.WebRequest]: make sure that the assembly containing this type is loaded.
  </code></pre>
  
  <p>I've tried using <code>Add-Type</code> to load <code>System.Net</code> and confirmed it is loaded with <code>[appdomain]::CurrentDomain.GetAssemblies()</code></p>
  
  <p>But the error persists</p>
  
  <p>No issues if the computer has PS 3.0</p>
  
  <p><strong>Edit:</strong> Full relevant code</p>
  
  <pre><code>InitialSessionState initial = InitialSessionState.CreateDefault();
  runspace = RunspaceFactory.CreateRunspace(initial);
  runspace.ApartmentState = System.Threading.ApartmentState.STA;
  runspace.Open();
  using (Pipeline pipeline = runspace.CreatePipeline()) {
    pipeline.Commands.AddScript(scriptText);
    &lt;invoke, read output etc&gt;
  }
  </code></pre>