I have a very strange issue which I cannot explain. We have and event receiver and within this we instantiate our own class that does all the work we need it to do. As part of this we pass in an SPWEB that we create. The code runs fine but when the code tries to get a list from the passed in SPWEB we get the "Detected use of SPRequest for previously closed SPWeb object" error being shown in the ULS logs.
The SPWeb is only being closed within the event receiver code after our class has done the work.
What is really strange is that if i run the same code from a Unit test no such error occurs so i am wondering if it is either an issue with the W3P process of the way sharepoint handles the threads of event receivers.
Here is the event receiver code
SPSite elevatedSite = new SPSite(properties.SiteId);
SPWeb elevatedWeb = elevatedSite.OpenWeb(properties.RelativeWebUrl);
MYClass myCLass = new MyCLass();
myClass.DoWork(elevatedWeb); // Cause error in ULS log
if (elevatedWeb != null)
if (elevatedSite != null)
If I run the same code in a unit test where I create a SPWeb object then the code run as I expect without any issues in the ULS logs.
nothing within MYClass calls dispose on the web object
I know I could but the Site and Web in a using, this does not make a difference to the error appearing or not
I have already used SPDisposeChecker and this shows no issues. I have gone through a number of posts around correctly disposing of SPWeb objects and believe that my code is doing this correctly
My code is working as expected but I have no idea how to solve this issue or if an issue actually exists. I do not want to release code that may cause a problem on production systems.