title: In PowerShell, object not loading though I call LoadWithPartialName
body: <p>I have a .ps1 file that I execute from PS prompt. At the top of the file I have:</p>
  
  <pre><code>[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  </code></pre>
  
  <p>and later in the code, it has:</p>
  
  <pre><code>$site = new-object Microsoft.SharePoint.SPSite $url;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Unable to find type [Microsoft.SharePoint.SPWeb]: make sure that the
    assembly containing this type is loaded.</p>
  </blockquote>
  
  <p>If I run the <code>LoadWithPartialName</code> statement from the prompt directly, then I can execute the script.</p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>--Update--</strong></p>
  
  <p>When I remove the void, making the code: </p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  </code></pre>
  
  <p>the error is unchanged because the <code>LoadWithPartialName</code> is executing without error.</p>
  
  <p><strong>--New Information--</strong></p>
  
  <p>It has something to do with adding a function with typed parameter of SPWeb.</p>
  
  <p>This works:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  $url = "http://siteurl/"
  $site = new-object Microsoft.SharePoint.SPSite $url;
  $site.Dispose();
  </code></pre>
  
  <p>And this works:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  function doSomething(){ }
  $url = "http://siteurl/"
  $site = new-object Microsoft.SharePoint.SPSite $url;
  $site.Dispose();
  </code></pre>
  
  <p>But this breaks if (you have to start a new PS session before it is an issue.  Also it doesn't matter if the function is before or after the first instantiation of SPSite:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  function doSomething(    [Microsoft.SharePoint.SPWeb] $web  ){ }
  $url = "http://siteurl/"
  $site = new-object Microsoft.SharePoint.SPSite $url;
  $site.Dispose();
  </code></pre>
  
  <p>I suppose a secondary work-around is to not type the parameter or put the load in another ps1. </p>