If I have an event receiver that handles the item added event, it fires whenever the list is modified. While debugging the event we see that it is firing over a non-existim item (properties.ListItem is null).

I have been handling this with the following one-liner:

if (properties.ListItem == null) return;

However, I feel that I am not getting the whole picture, and that I may end up causing more problems for not handling this correctly.

Is there a reason the item added event fires when the list is modified? Is there a better way to handle this, or to prevent this event from firing in this situation?

Edit: the change I am making to the list is adding a field programmatically during feature activation.

  • properties.ListItem in item adding event is always null. At that moment list item is still is not exists – Ruslan Dayanov Sep 29 '14 at 13:42
  • @RuslanDayanov thanks for pointing that out! Indeed, that was an error on my part. I am fixing the question. However, the same event firing happens on item added events as well, when the item should exist. – Renan Sep 29 '14 at 13:52
  • What kind of changes are you making to list? I've tested event receiver and nothing has happened. And check your list event receivers with sharepoint manager. – Ruslan Dayanov Sep 29 '14 at 14:15
  • I am adding a field programmatically, during feature activation. Sandbox solution. – Renan Sep 29 '14 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.