SPC110235: Do not dispose SPItemEventProperties.Web.Site

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

TypeName: DoNotDisposeSPItemEventPropertiesWebSite
CheckId: SPC110235
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

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

Bad Coding Practice

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

Remarks

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

Links

comments powered by Disqus