I have created a web part in visual studio, it deploys fine, but when I try to add it to a page I get the following error:

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

I read that this could happen due to disposing of objects too soon, so I changed

using (SPSite site = SPContext.Current.Site)

to this

using (SPSite site = new SPSite(SPContext.Current.Site.Url))

but it didn't fix anything. Does anyone have any idea why this would happen?


I'm not using SPWeb but I use the SPSite object here:

using (FullTextSqlQuery fullTextSqlQuery = new FullTextSqlQuery(site))
  • Can you post your SPWeb code as well?
    – Dave Wise
    Commented Nov 8, 2011 at 17:39
  • I'm not using SPWeb. I went ahead and posted the code that is using the SPSite object though. Commented Nov 8, 2011 at 17:55

3 Answers 3


After correcting your code, please make sure that your web part is the only one on the page. It may be that other custom web parts are using the uncorrected code and thus disposing of the SPSite object before your web part can access it.


Your first code snippet would produce exactly the error message you saw, the second should fix it.

Try an IISReset, just to be absolutely sure your latest code is being loaded?

  • Yes, you shouldn't dispose SPContext.Current.Site at all.
    – SPDoctor
    Commented Nov 8, 2011 at 17:26
  • I did an IIS reset, and I'm still getting the same error :( Commented Nov 8, 2011 at 17:41
  • 1
    Is this the only custom web part on that page? use the ?contents=1 url trick to make sure
    – Dave Wise
    Commented Nov 8, 2011 at 17:57
  • No it's not the only one. I only get the error when I try to add this web part though. Commented Nov 8, 2011 at 18:36
  • Ooohhh are you thinking it might be caused by another web part disposing incorrectly? Commented Nov 8, 2011 at 18:37

You should use SPContext.Current.Site to access the current site. Do not create any new SPSite object can be taxing on resources, you can use the current site from the SPContext.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.