Friday, 3 May 2013

Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))


In my web part I used followig code
I used to write the code like this
using (SPSite _site = SPContext.Current.Site)
{
  using (SPWeb _web = site.RootWeb)
  {
   // your code
  }
}
To correct this issue use code like following in my web part

SPSite currSite = SPContext.Current.Site;
SPWeb currWeb = currSite.RootWeb;
using (SPSite eSite = new SPSite(currSite.ID))
{
 using (SPWeb eWeb = eSite.OpenWeb(currWeb.ID))
 {
    //Your code
 }
}
Happy coding…

No comments:

Post a Comment