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.
CheckId | SPC110242 |
---|---|
TypeName | DoNotDisposeSPWebParentWeb |
Severity | CriticalWarning |
Type | Assembly |
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 Practice
{
using (SPWeb web = site.OpenWeb())
{
SPWeb parentWeb = web.ParentWeb; //No explicit dispose required.
}
}
Rule relates to SPDisposeCheckId 'SPDisposeCheckID_640'. To ignore this rule add the attribute '[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_640, "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", "SPC110242:DoNotDisposeSPWebParentWeb", Justification = "Provide reason for suppression here")]