title: "Object reference not set to an instance of an object." with NuGet.VisualStudio.IVsPackageInstaller.InstallPackage
body: <p>The following code is raising <strong>NullReferenceException</strong> ("Object reference not set to an instance of an object.") on Visual Studio 2015, NuGet.VisualStudio v3.3).</p>
  
  <pre><code>try
  {
      this.PackageInstaller.InstallPackage(packageSource, project, packageId, version, ignoreDependencies);
  }
  catch (Exception ex)
  {
      string error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.RES_Error_InstallingNuGetPackage, packageId, project.Name);
      throw new NuGetServiceException(error, ex);
  }
  </code></pre>
  
  <p>The PackageInstaller is an instance of NuGet.VisualStudio.IVsPackageInstaller.</p>
  
  <p>The problem seems to have something to do with the values of version, and may be packageSource.</p>
  
  <p>When this error is raised the values are:</p>
  
  <pre><code>packageSource = "All"
  version = null
  </code></pre>
  
  <p>If I change the value of <code>version</code> to the latest available version of the package ("3.00.00.1041") then the exception is <strong>InvalidOperationException</strong> ("Unable to find version '3.00.00.1041' of package 'Primavera.Core.Patterns.Models'.").</p>
  
  <p>This does not make any sense because this works perfectly in the Package Manager Console and it installs exactly that version. It seems to be a bug in the NuGet.VisualStudio code base.</p>
  
  <p>Any ideas?</p>