Declare Scope for Receivers in Site Features |
If event receivers are used within a feature with scope 'Site' the attribute 'Scope' should be specified.
CheckId | SPC016002 |
---|---|
TypeName | DeclareScopeForReceiversInSiteFeatures |
Severity | CriticalWarning |
Type | Receivers |
The Receiver element should specify attribute 'Scope' with value 'Site' or 'Web'. See MSDN: 'When a SharePoint Feature is scoped to the site collection level, a 'Receivers' tag is potentially ambiguous. The tag can indicate either site-wide event binding or event binding for the top-level site. Note, however, that the default behavior is to scope to the site level. Therefore, when you scope a Feature to the site collection level, use the attribute named Scope to specify the intended scope. When you set this attribute to 'Site', event receivers that are defined inside a Feature that is scoped to the site collection are then bound at the site collection level. When the attribute is set to 'Web', event receivers that are defined for a Feature of a site collection are bound at the root Web site of that site collection.'. See sample below:
<Receivers
ListTemplateId="104"
Scope="Site">
<Receiver>
<Name>SimpleUpdateEvent</Name>
<Type>ItemUpdating</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>SimpleUpdateEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=10b23036c9b36d6d</Assembly>
<Class>MS.Samples.SimpleItemUpdateHandler</Class>
<Data></Data>
</Receiver>
</Receivers>
</Elements>
To suppress this violation in XML SharePoint code add the following comment right before the XML tag which causes the rule violation. Learn more about SuppressMessage here.