Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

UPDATE:

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

using (FullTextSqlQuery fullTextSqlQuery = new FullTextSqlQuery(site))
share|improve this question
    
Can you post your SPWeb code as well? –  Dave Wise Nov 8 '11 at 17:39
    
I'm not using SPWeb. I went ahead and posted the code that is using the SPSite object though. –  Abe Miessler Nov 8 '11 at 17:55
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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?

share|improve this answer
    
Yes, you shouldn't dispose SPContext.Current.Site at all. –  SPDoctor Nov 8 '11 at 17:26
    
I did an IIS reset, and I'm still getting the same error :( –  Abe Miessler Nov 8 '11 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 Nov 8 '11 at 17:57
    
No it's not the only one. I only get the error when I try to add this web part though. –  Abe Miessler Nov 8 '11 at 18:36
    
Ooohhh are you thinking it might be caused by another web part disposing incorrectly? –  Abe Miessler Nov 8 '11 at 18:37
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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