SPC110243: Do not dispose SPList.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: DoNotDisposeSPListParentWeb
CheckId: SPC110243
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Do not call Dispose on SPList.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())
  {
    SPList list = web.Lists["Announcements"];
    SPWeb parentWeb = list.ParentWeb; //No explicit dispose required.
  }
}

Remarks

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

Links

comments powered by Disqus