CRM plugin invinite loop prevention RRS feed

  • Question

  • Hi,

    i read already a lot about the context.Depth property and i understood it completly, but my problem is this comment: "now exit - if the derived plug-in has incorrectly registered overlapping event registrations" in a newly created plugin by visual studio.

    Context.Depth and this exit here handle different cases of problems which can occur right?

    And the other question is why i need this exit here, beccause when the plugin iterates over the list of registrated steps like "create" there is a FirstOrDefault(). So the plugin takes always the first action even if there are more actions registrated. As you see in the code stub below.

    I don't understand this comment and what it is for!

    The following code i copied out of the auto generated project for microsoft crm when you create a new plugin with visual studio 2012.

    // Iterate over all of the expected registered events to ensure that the plugin
                    // has been invoked by an expected event
                    // For any given plug-in event at an instance in time, we would expect at most 1 result to match.
                    Action<LocalPluginContext> entityAction =
                        (from a in this.RegisteredEvents
                         where (
                         a.Item1 == localcontext.PluginExecutionContext.Stage &&
                         a.Item2 == localcontext.PluginExecutionContext.MessageName &&
                         (string.IsNullOrWhiteSpace(a.Item3) ? true : a.Item3 == localcontext.PluginExecutionContext.PrimaryEntityName)
                         select a.Item4).FirstOrDefault();

    Kind Regards


    • Edited by Markus Benz Thursday, November 21, 2013 9:31 AM
    Thursday, November 21, 2013 9:30 AM


  • Hi Markus,

    You are right - this comment isn't quite correct and I suspect that it was there from a previous version that didn't use a LINQ query but rather itterated in a foreach loop.

    The FirstOrDefault will pick a matching event registration and if non, then the Execute will exit without running any code.



    Scott Durow
    Blog www.develop1.net    Follow Me
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, November 21, 2013 10:52 PM