none
SPLimitedWebPartManager.SaveChanges() throws "List not found" error RRS feed

  • Question

  • I have a big custom 2010 application/site. I migrated the 2010 site to 2013 (2010 mode). There is a custom feature that allows me to create a new sharepoint site programmatically. Code works upto here. Then i add web parts to the home page and assign permissions to the web parts (programmatically). This is where the code fails. Permissions are assigned to the new site, all lists, all pages but when I assign permissions to the web parts (added on the homepage), I get "list not found" error. Code works fine in 2010 but does not work in 2013 (2010 mode).

    Here is the code:

     using (SPLimitedWebPartManager WPManager = web.GetLimitedWebPartManager(page, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared)
    {

       foreach (System.Web.UI.WebControls.WebParts.WebPart wp in WPManager.WebParts)
       {              

          //assign permissions

        WPManager.SaveChanges(wp); //--------> This line throws error

       }

    }

    Error:

    mscorlibException has been thrown by the target of an invocation.Microsoft.SharePoint.SPException: List does not exist.

    The page you selected contains a list that does not exist.  It may have been deleted by another user. ---> System.Runtime.InteropServices.COMException: List does not exist.

    The page you selected contains a list that does not exist.  It may have been deleted by another user.
       at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)
       at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount)

    Background: I am using 2010 web template to create new site in 2013. Could that be the issue? I was hoping that since migrated site runs in 2010 mode, that wouldn't be a problem. I already deactivated and activated the publishing feature. I have tried everything I could think of and am on the verge of giving up.

    I am posting here hoping that someone might have experienced similar issue and might be able to share their experience and knowledge. Any help, any pointers, any information, any guidance will be very helpful and I will be highly obliged.

    Thank you

    Henry

    Tuesday, December 13, 2016 9:10 PM

All replies

  • Hi Henry,

    This error is very common.

    Could you please let us know how you assign the permissions to web parts(the code part for assigning permission) for further research?

    Best Regards,

    Victoria

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, December 14, 2016 8:03 AM
    Moderator
  • Hi Victoria,

    Thanks for responding! Finally, someone responded! I was surprised that in this huge community of SharePoint experts, no one had experienced this problem before or cared to share their insights. Anyway, I did more troubleshooting last night and I have pin-pointed the issue but still do not have a solution. By assigning permission to webpart, what I mean is, setting target audience. Here is the code:

    wp.AuthorizationFilter = string.Format(";;;;{0}", string.Join(",", arrGroups.ToArray())); //--> arrGroups contains "Site_Readers, Site_Contributors, Site_Admins"

    WPManager.SaveChanges(wp);

    This code works in 2010 but throws error in 2013. I checked the web template that I use to create the site programmatically. I also notice that this code works for custom web parts but fails for out of the box XSLTListViewWebParts, for example, Calendar and Announcements web parts. In the site, we provision OOTB Calendar and Announcements lists using web template we created in 2010. Here is the code:

    <View List="Lists/Announcements" BaseViewID="1" MobileView="TRUE" WebPartZoneID="LandingPage" WebPartOrder="2" />

    We have a custom publishing page that has a webpart zone called "LandingPage". So the problem is with the "List" attribute. Error says "list does not exist" whereas "Lists/Announcements" does exist and is accessible via UI. I am thinking that it has something to do with the GUID of the list. May be that has changed in SP 2013 but I am not sure how to resolve this problem. As I said, there is no error when we set target audience for custom web part and here is how we provision custom web part:

    <AllUsersWebPart WebPartZoneID="LandingPage" WebPartOrder="3">
              <![CDATA[
                <webParts>
                  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
                    <metaData>
                      <type name="Solato.WebParts.ProjectDescription.ProjectDescription, Solato.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=76d6d9a068ea9155"/>
                      <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
                    </metaData>
                    <data>
                      <properties>
                        <property name="Title" type="string">Project Description</property>
                        <property name="Description" type="string">Displays Project Description</property>
                          <property name="Height" type="unit">100px</property>
                      </properties>
                    </data>
                  </webPart>
                </webParts>
              ]]>
            </AllUsersWebPart>

    So what I am thinking is, if I provision OOTB webparts using CDATA, that might resolve the issue but I don't know how to use "List" attribute in CDATA.

    I hope I have clearly stated the problem. Let me know if you need more information to understand the issue. I will be very very thankful if you could share some insights as I am stuck and don't know where to look for a solution.

    p.s. since this code works in 2010 and does not work in 2013, I believe there is something that is not working in 2013 environment although we are using 2010 mode after migrating the application to 2013. May be there is another way of setting target audience in 2013 but then the code should fail for custom web parts also but since that works, I am thinking there is something wrong with the web part provisioning using this code in 2013. Thanks

    Wednesday, December 14, 2016 4:25 PM
  • Hi Henry,

    Please check ULS logs to get more detailed error message for further research.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, December 20, 2016 2:24 AM
    Moderator
  • I'm facing the same issue. Did you find a solution?

    The same code works fine in powershell but not in my code 

    C#:

    var wpm = spWeb.GetLimitedWebPartManager(url, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
    var part = wpm.WebParts[0];
    part.AuthorizationFilter = ";;;;"+groupName;
    wpm.SaveChanges(part);

    PowerShell:

    $wpm = $web.GetLimitedWebPartManager($url,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
    $part = $wpm.WebParts[0]
    $part.AuthorizationFilter=";;;;"+$groupName
    $wpm.SaveChanges($part)

    Thank you

    Edit: It works vor ListViewWebPart, but not for XsltListViewWebPart
    • Edited by ManuWa Tuesday, September 12, 2017 11:58 AM
    Monday, August 21, 2017 4:53 PM
  • Hello, I have the exact same issue. Did you found a solution for this?

    Wednesday, September 13, 2017 12:35 PM