SPC110237: Do not dispose SPFeatureReceiverProperties.Feature.Parent

The object in SPFeatureReceiverProperties.Feature.Parent (e.g. used in a SPFeatureReceiver) should not be disposed.

TypeName: DoNotDisposeSPFeatureReceiverPropertiesFeatureParent
CheckId: SPC110237
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Do not call Dispose on SPFeatureReceiverProperties.Feature.Parent (which is either SPWeb, SPSite etc.). See sample:

Bad Coding Practice

public class FeatureReceiver : SPFeatureReceiver
{
  public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {
    SPWeb web = properties.Feature.Parent as SPWeb;
    web.Dispose(); // DO NOT DO THIS.
  }
}

Remarks

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

Links

comments powered by Disqus