title: "The specified view is invalid" in call to LimitedWebPartManager.AddWebPart in SharePoint 2010
body: <p>This code used to work in WSS 3.0 / MOSS 2007 in FeatureReceiver.FeatureActivated:</p>
  
  <pre><code>using (SPLimitedWebPartManager limitedWebPartManager = Site.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared)) {
      ListViewWebPart listViewWebPart = new ListViewWebPart {
          Title = title,
          ListName = list.ID.ToString("B").ToUpper(),
          ViewGuid = view.ID.ToString("B").ToUpper()
      };
      limitedWebPartManager.AddWebPart(listViewWebPart, zone, position);
  }
  </code></pre>
  
  <p>I'm trying to convert to SharePoint 2010 and it now fails with:</p>
  
  <pre><code>System.ArgumentException: The specified view is invalid.
  at Microsoft.SharePoint.SPViewCollection.get_Item(Guid guid)
  at Microsoft.SharePoint.WebPartPages.ListViewWebPart.EnsureListAndView(Boolean requireFullBlownViewSchema)
  at Microsoft.SharePoint.WebPartPages.ListViewWebPart.get_AppropriateBaseViewId()
  at Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartInternal(SPSupersetWebPart superset, Boolean throwIfLocked)
  at Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPartInternal(WebPart webPart, String zoneId, Int32 zoneIndex, Boolean throwIfLocked)
  at Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPart(WebPart webPart, String zoneId, Int32 zoneIndex)
  </code></pre>
  
  <p>Interestingly enough when I run it from a unit test it works, it only fails in FeatureActivated.  When I debug with Reflector it is failing on this line:</p>
  
  <pre><code>this.view = this.list.LightweightViews[new Guid(this.ViewGuid)];
  </code></pre>
  
  <p>list.LightweightViews only returns one view, the default view, even though list.Views returns all of them.  When running from a unit test LightweightViews returns all of my views.  I have no idea what LightweightViews is supposed to mean and I'm running out of ideas.  Anyone else got any?</p>