SPC110236: Do not dispose SPItemEventProperties.ListItem.Web.Site

The object in SPItemEventProperties.ListItem.Web.Site (e.g. used in a SPItemEventReceiver) should not be disposed.

TypeName: DoNotDisposeSPItemEventPropertiesListItemWebSite
CheckId: SPC110236
Severity: CriticalWarning
Type: AssemblyFileReference

Do not call Dispose on SPItemEventProperties.ListItem.Web. See sample:

Bad Coding Practice

public class ItemEventReceiver : SPItemEventReceiver
  public override void ItemAdded(SPItemEventProperties properties)
     SPSite site = properties.ListItem.Web.Site;
     site.Dispose(); // DO NOT DO THIS.


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


comments powered by Disqus