KNOWLEDGE SHEET – Stale Objects & HTTP 500 Error

KNOWLEDGESHEET

 

Stale Objects & HTTP 500 Error

 

 

Scenario – I was working for Squadron > Permissions management module. The SPWeb objects in collection were invoking Update() method multiple times.  Additionally the same SPWeb object were used in child SPList objects.  As these SPWeb objects were obsolete, invoking the Parentweb.Update() from child objects made the entire web application fault by HTTP 500 error.

 

 

Solution: Create new SPWeb objects in the child list again

 

public void InvokeUpdate(SPList list)

 

{

 

  SPSecurity.RunWithElevatedPrivileges(delegate()

 

  {

 

    using (SPSite site = new SPSite(list.ParentWeb.Site.Id))

 

    {

 

      using (SPWeb web = site.OpenWeb(list.ParentWeb.Id))

 

      {

 

        site.AllowUnsafeUpdates = true;

 

        site.Update();

 

        site.AllowUnsafeUpdate = false;

 

      }

 

    }   

 

  });

 

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *