Home > Microsoft SharePoint 2010 > Visual web part error: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))

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

Yesterday I was working with visual webpart , While development my visual webpart works as expected, but when i deployed the more then one instance of Visual webparts on a page, it gives me error “Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))”, while searching about this and reading on MSDN, i was wondering there is some thing wrong with my code and the related to SPSite or SPWeb object disposal.

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…

Advertisements
  1. Surajit Mukherjee
    February 21, 2012 at 4:12 pm

    Thanks Prasad for the post. I faced the same problem. Your solution really works!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: