Just trying to understand what is happening here. I have an event receiver that currently is not working (yet to find the bug).
The code is incredibly simple and uses 2 "using" statements as per best practise in order to ensure the the objects are disposed of.
When I look in the ULS logs and get the error for my event receiver it is immediatly followed by the "SPRequest object was not disposed" messages that I'm sure you have seen.
Given that my code is within a using statement how can this be true?
If there is a problem does "using" not clean up after itself like a try/catch may?
I could change my code to be try/catch and clean up within the finally block but I thought using might clean up.
Is this not the case or am I misunderstanding something?
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
string theCourseName = properties.ListItem.Title;
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPListTemplate theTemplate = web.ListTemplates["CourseFeedback"];
web.Lists.Add(theCourseName + ", Feedback", "Feedback from the course you attended", theTemplate);
}
}
}