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.
CheckId | SPC110243 |
---|---|
TypeName | DoNotDisposeSPListParentWeb |
Severity | CriticalWarning |
Type | Assembly |
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 Practice
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Announcements"];
SPWeb parentWeb = list.ParentWeb; //No explicit dispose required.
}
}
Rule relates to SPDisposeCheckId 'SPDisposeCheckID_635'. To ignore this rule add the attribute '[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_635, "Caller will dispose")]' to your method.
To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.
[SuppressMessage("SPCAF.Rules.MemoryDisposalGroup", "SPC110243:DoNotDisposeSPListParentWeb", Justification = "Provide reason for suppression here")]