SharePoint 2010 / MSOCAF - Disposable type not disposed Microsoft.SharePoint.SPWeb

If you ever get the following warning through the MSOCAF Wizard,

Disposable type not disposed Microsoft.SharePoint.SPWeb

modify the the following contents:
1
2
3
4
5
6
7
using (SPSite _SPSite = properties.Feature.Parent as SPSite)
{
     using (SPWeb _SPWeb = _SPSite.RootWeb)
     {
          ...
     }
}
to the following:
1
2
3
4
5
using (SPSite _SPSite = properties.Feature.Parent as SPSite)
{
     SPWeb _SPWeb = _SPSite.RootWeb;
     ...
}
as no explicit rootweb dispose is required. Alternatively, you could also do,
1
SPWeb _SPWeb = SPContext.Current.Site.RootWeb;

Comments

Popular posts from this blog

C# - ListView Item Spacing (Padding)

C# - Performance Counters

ASP.NET MVC - Disabling Browser Link