This project is read-only.

Incorrect dispose?

Oct 1, 2010 at 1:49 PM

Hi,

Dont know if someone have experienced the same problem but...

When we use the webpart in combination with the note board web part, we get an error about database access. After investigating the logs, we found the following:

 

Detected use of SPRequest for previously closed SPWeb object.  Please close SPWeb objects when you are done with all objects obtained from them, but not before.  Stack trace:    at Microsoft.SharePoint.SPField.get_FieldsSAFullXML()     at Microsoft.SharePoint.SPField.get_Node()

....

 

But, the note board worked before we added the site directory webpart. So, i had a look at the code:

GlobalMethods.cs, Line 274:

using (SPWeb thisWeb = thisSite.RootWeb)

...

And

SiteDataWebpart.cs, Line 149:

using (SPWeb thisWeb = SPContext.Current.Web)

....

 

I have tried changing the lines to not dispose of webs obtained through SPContext, but rather use the OpenWeb() method instead. The result is that the note board and the Site Directory can now co-exist on the same page.

Someone correct me if im wrong, but I dont believe you should dispose of SPContext.Current.Site, or SPContext.Current.Web - ever...?

'SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.'

Taken from the best practices:

http://msdn.microsoft.com/en-us/library/aa973248%28office.12%29.aspx

 

Have anyone experienced similar problems?

Best Regards

Lars

 

Oct 4, 2010 at 9:02 AM

Lars,

Thanks for this, you are quite right in saying that the disposal is not used correctly in this version of the code.

Please log this in the issue tracker and we'll address it in the next release.