Article ID: 2647429 - Last Review: December 6, 2011 - Revision: 3.0

SharePoint 2010: Synchronous itemAdded event receiver results in null reference exception

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Expand all | Collapse all

SYMPTOMS

Consider the following scenario:

You develop a custom event receiver that executes against the itemAdded event for a Wiki pages library. The event receiver breaks permission on a newly created page in the library then adds a new set of permissions.

In this scenario, the item does get added with the correct permissions; however an error is generated that looks similar to the following:

System.NullReferenceException: Object reference not set to an instance of an object.

CAUSE

The issue occurs within a synchronous ItemAdded Event receiver, in this particular case, a wiki page or a document library. If a new security scope is created inside the event receiver, the list that contains the item will be unaware of the new scope until the event receiver is finished and the list can be updated. Because of this, any call to retrieve the scopes from the list will not include the new scope, and lead to an error.

RESOLUTION

This issue has been identified as a limitation in the current design of event receivers. There are no current plans to modify the behavior of event receivers to allow for this scenario.

MORE INFORMATION

The ability to add synchronous event receivers for itemAdded event is new to SharePoint 2010. Two workarounds are suggested for this particular scenario:

1.) Use asynchronous event receivers instead.
2.) Use the itemUpdated event receiver instead.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use (http://go.microsoft.com/fwlink/?LinkId=151500) for other considerations.

APPLIES TO
  • Microsoft SharePoint Foundation 2010
  • Microsoft SharePoint Server 2010
  • Microsoft SharePoint Server 2010 Service Pack 1
Keywords: 
KB2647429