Saturday, February 18, 2012

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;
Post a Comment