Tuesday, 8 July 2014

Attempted to use an object that has ceased to exist in Sharepoint

In one of the pages of my SharePoint application, I added a Links web part (web part that shows the contents of the a links list). Pretty simple. Then, I se tthe "XSL Link" property so that the results were customised in a certain style. Then I got this really strange error:
Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED)) 
After some searching I understood it meant that the current SPContext could not be accessed. I then realised that another (custom) web part in the page was destroying the SPContext object after use, so when the Links web part (OOTB) tried to use it, it couldn't.
Look for anything like
(SPWeb site SPContext.Current.Site) {...}

in your custom web part code. This is wrong. You must not dispose the current site object. Instead you can use something like:
using (SPWeb elevatedSite = elevatedsiteColl.OpenWeb(siteID)) { ... }
Guid siteID = SPContext.Current.Web.ID;

No comments:

Post a Comment