SPC110242: Do not dispose SPWeb.ParentWeb

An earlier version of the documentation recommended that the calling application should dispose of the SPWeb.ParentWeb. This is no longer the official guidance. The dispose cleanup is handled automatically by the SharePoint framework.

TypeName: DoNotDisposeSPWebParentWeb
CheckId: SPC110242
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Do not call Dispose on SPWeb.ParentWeb. MSDN: An earlier version of this article recommended that the calling application should dispose of the SPWeb.ParentWeb. This is no longer the official guidance. The dispose cleanup is handled automatically by the SharePoint framework. See sample from MSDN:

Good Coding Practice

using (SPSite site = new SPSite("http://localhost"))  
{
  using (SPWeb web = site.OpenWeb())
  {
    SPWeb parentWeb = web.ParentWeb; //No explicit dispose required.
  }
}

Remarks

Rule relates to SPDisposeCheckId 'SPDisposeCheckID_640'. To ignore this rule add the attribute '[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_640, "Caller will dispose")]' to your method.

Links

comments powered by Disqus