Expand Minimize

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:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <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.

<!-- "SuppressMessage":{"rule":"SPC016002:DeclareScopeForReceiversInSiteFeatures","justification":"Provide reason for suppression here"} -->
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.