SPC110232: Do not dispose SPWebEventProperties.Web

The SPWeb object in SPWebEventProperties (e.g. used in a SPWebEventReceiver) should not be disposed.

TypeName: DoNotDisposeSPWebEventPropertiesWeb
CheckId: SPC110232
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

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

Bad Coding Practice

public class WebEventReceiver : SPWebEventReceiver
{
  public override void WebAdding(SPWebEventProperties properties)
  {
    SPWeb web = properties.Web;
    // ..
    web.Dispose(); // DO NOT DO THIS.
  }
}

Remarks

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

Links

comments powered by Disqus