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:
using (SPSite _SPSite = properties.Feature.Parent as SPSite)
{
     using (SPWeb _SPWeb = _SPSite.RootWeb)
     {
          ...
     }
}
to the following:
using (SPSite _SPSite = properties.Feature.Parent as SPSite)
{
     SPWeb _SPWeb = _SPSite.RootWeb;
     ...
}
as no explicit rootweb dispose is required. Alternatively, you could also do,
SPWeb _SPWeb = SPContext.Current.Site.RootWeb;

Comments

Popular posts from this blog

C# - ListView Item Spacing (Padding)

C# / SQL - Performing Distributed Transactions

IIS / ASP.NET - Disabling Compatibility Mode/View (Internet Explorer)