4

We have a SharePoint 2010 On-Prem solution.

I have an ItemAdded event receiver which has been made synchronous using the Synchronization property. Now, when this event receiver fires, I have used the properties.Web property to get a reference to the current web as per guidance here: http://blogs.msdn.com/b/rogerla/archive/2009/11/30/sharepoin… .

Now when this event receiver fires, the ULS logs report the dreaded "An SPRequest object was not disposed before the end of this thread" error. Since the properties.Web is managed by SharePoint, I have not disposed it explicitly in my code. But, if I do a properties.Dispose() at the end of my code, then the error is no longer reported.

The funny thing is, If I make the eventreceiver async, the error does not show up at all.

That means a weird race condition is developing where if the event receiver is synchronous, properties.Web is somehow not disposed before the thread ends(?) and the error is logged in ULS.

Has anybody seen this kind of behavior before? I could potentially do a properties.Dispose() at the end of my code but I am not sure what the impact will be as all the guidance states you do not need to dispose objects owned by SharePoint.

2

I think that you should not to use properties.Dispose() method, furthermore you should not to use properties.Web.Dispose(). I'm sure these objects are used in SharePoint later.

As workaround you can try to use this snippet:

using (SPWeb web = properties.OpenWeb())
{
    //code          
}
  • This will be a valid workaround but I also have another event receiver where I use priperties.ListItem which is exhibiting same behavior. I think that is because of the ListItem.Web object. There I think I will have to resort to properties.Dispose() – Vardhaman Deshpande Jul 28 '14 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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