1

I have a Remote Event Receiver attached to a list on my SP web and code that then runs on the ItemUpdated event:

var web = clientContext.Web;
var site = clientContext.Site;
var list = web.Lists.GetById(properties.ItemEventProperties.ListId);
var item = list.GetItemById(properties.ItemEventProperties.ListItemId);
var memberGroup = web.AssociatedMemberGroup;

clientContext.Load(web);
clientContext.Load(web.AllProperties);
clientContext.Load(item);
clientContext.Load(site);
clientContext.Load(memberGroup);
clientContext.ExecuteQuery();

item.BreakRoleInheritance(true, true);
item.Update();
var roleAssignment = item.RoleAssignments.GetByPrincipal(memberGroup);
roleAssignment.RoleDefinitionBindings.RemoveAll();
roleAssignment.Update();
clientContext.ExecuteQuery();

But sometimes the second half of the code breaks (for example the memberGroup wasn't found) and then the strange part comes.

I get an exception at the last clientContext.ExecuteQuery() that says Value cannot be null and then it goes back to the start of the code and tries to redo it all over again. The same happens if I add a try catch-statement around the last part, like this;

try{
   clientContext.ExecuteQuery();
}
catch {
   throw;
}

When I try to follow the code in the debugger it just loops over my code over and over again until I actually delete the list from the web.

Does anyone know why this is and how I break out of it?

1

Since it an ItemUpdated it is calling the same code again and again. In Server object model we have this.EventFiringEnabled = false; to prevent the event from firing again. You may have to perform some checks to avoid the update operation recurrence. Here is a somewhat similar question: Remote Event Receiver on updated will be fired multiple time

  • This was correct, but I still have no idea how to cancel the event receiver. Now I'm doing a check for the lastmodified time and it feels like a shady and unreliable way.. – stinaq Mar 28 '14 at 15:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.