Do not dispose SPSite.RootWeb |
An earlier version of the documentation indicated that the calling application should dispose of the SPSite.RootWeb property just before disposing of the SPSite object that is using it. This is no longer the official guidance. The dispose cleanup is handled automatically by the SharePoint framework.
CheckId | SPC110241 |
---|---|
TypeName | DoNotDisposeSPSiteRootWeb |
Severity | CriticalWarning |
Type | Assembly |
Do not call Dispose on SPSite.RootWeb. MSDN: An earlier version indicated that the calling application should dispose of the SPSite.RootWeb property just before disposing of the SPSite object that is using it. This is no longer the official guidance. The dispose cleanup is handled automatically by the SharePoint framework. Additionally, SPSite properties LockIssue, Owner, and SecondaryContact used the RootWeb property internally. Given the updated guidance for RootWeb, it is no longer advisable to call the Dispose method on the SPSite.RootWeb property whenever any of these properties are used.
Rule relates to SPDisposeCheckId 'SPDisposeCheckID_655'. To ignore this rule add the attribute '[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_655, "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", "SPC110241:DoNotDisposeSPSiteRootWeb", Justification = "Provide reason for suppression here")]