SPC110233: Do not dispose SPItemEventProperties.Web

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

TypeName: DoNotDisposeSPItemEventPropertiesWeb
CheckId: SPC110233
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

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

Bad Coding Practice

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

Remarks

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

Links

comments powered by Disqus