0

I am debugging on SP2010 environment. There is an Event receiver listening to particular list, the first few lines of code is:

public override void ItemAdded(SPItemEventProperties properties)
        {
            try
            {
                SPList listOfEntries = properties.List;
                if (listOfEntries.Title == "Command")

I added a breakpoint at the line "SPList listOfEntries = properties.List".

When I added an item to "Command" list manually, the breakpoint will be reached.

There is a SPD list workflow and the workflow create a task asking for approval. If the user reject the task immediately after the task is assigned, a new item will be added to "Command" list by the workflow. In this way, the Event Receiver will not be triggered (the breakpoint will not be reached, too). I change the VS debugger to monitor OWSTimer and this time breakpoint is reached. On visual studio debug screen I mouseover every variable inside this function. I found all variables are carrying the wrong item! For example,

SPList myList = web.Lists["ListA"];
SPQuery myQuery = new SPQuery();
myQuery.Query = "<Where><Geq><FieldRef Name = \"Title\"/>" + "<Value Type = \"Text\">"

In VS debug mode, "myList" is carrying "ListZ" (which is not within this function). myQuery is carrying web.Lists["ListA"]. All variable goes crazy. That's why my event receiver not work??! Or actually my VS have bug?

If the user wait for 3 minutes before reject the task, the same item will be added to "Command" list by the workflow, the Event Receiver will be triggered this time.

If I check with VS debugger in this situation, all variables show normal value....

It doesn't make sense to me. If my event receiver code have bug, it should at least reach the breakpoint. However it is not fired at all...

Do you have any clue on what is happening?

7
  • Is runwithelevatedprivilegesused ? If yes, then SPD workflow will not trigger. Commented Nov 17, 2016 at 6:50
  • Do you have any SPD workflow attached on "Command" list ? Commented Nov 17, 2016 at 6:55
  • @MonicaJagani, I don't find "runwithelevatedprivilegesused" in the code and the designer workflow. Also, no SPD workflow attached at command list.
    – Mark L
    Commented Nov 17, 2016 at 7:29
  • Not sure if it helps but can you try to change the sequence number of the event receiver (check element.xml). It might help but not sure. Commented Nov 17, 2016 at 8:01
  • Have you looked for any clues in the ULS logs ?
    – HarryB
    Commented Nov 17, 2016 at 12:10

1 Answer 1

1

i think your battling between asynchronous vs asynchronous events occurring that your trying to capture.

the problem is you have a workflow which is independent of the list events.

quickest and simplest solution is to have a wait for 3 or 5 minutes delay before sending out the task message to the user giving time for the workflow event to complete and for the event to trigger.

3
  • I agree it would be a feasible work around. But why the event receiver is not fired at all? Will it just ignore some event when it is busy?
    – Mark L
    Commented Nov 18, 2016 at 1:13
  • what EventReceiver Class are you using?
    – Ali Jafer
    Commented Nov 18, 2016 at 9:42
  • I have updated my new finding about debugger. class SPItemEventReceiver is using.
    – Mark L
    Commented Nov 21, 2016 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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