locked
Strange behavior of plugin execution !!!! RRS feed

  • Question

  • Hi All,

    I have a strange behavior of my plugin. in fact my plugin is regestred on the salesorder entity on the Fulfill stage, the plugin create some record X attached to the salesorder onpostfulfill. some how I found the record X of a salesorder Y attached to another salesorder Z. its seams an attachement of previous execution of the fulfill message for another record of salesorder.

    to be clair , after two execution of the plugin the value of the new_salesorderid (lookup of relation ship on the entity X) does'nt change value.

    Thanks for Help.

    Tuesday, August 31, 2010 12:58 PM

Answers

  • what do you think about this link, can you explain to me more: Thanks

    How CRM instantiates the plug-in?

    CRM instantiates the Plug-in class on the first activation of the plug-in. CRM will call plug-in's constructor. Once the object is instantiated, CRM calls the Execute method on the object. For performance reasons, CRM DOES NOT dispose of the object after it completes execution. So CRM caches the object and calls Execute on the same object instance on the next activation of the plug-in. CRM will flush its cache when any properties are changed on the pluginassembly, plugintype, sdkmessageprocessingstep, sdkmessageprocessingstepimage entities for registration. This means that you need to be very careful when defining class-level variables in the plug-in class as multiple threads can execute the code at one time.

     

    http://blogs.msdn.com/b/crm/archive/2008/11/18/member-static-variable-and-thread-safety-in-plug-in-for-crm-4-0.aspx

     

    • Marked as answer by BERKAYA Hedi Thursday, September 2, 2010 2:30 PM
    Tuesday, August 31, 2010 2:05 PM

All replies

  • you may need to paste your code here to help resolve this.
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, August 31, 2010 1:44 PM
    Moderator
  • what do you think about this link, can you explain to me more: Thanks

    How CRM instantiates the plug-in?

    CRM instantiates the Plug-in class on the first activation of the plug-in. CRM will call plug-in's constructor. Once the object is instantiated, CRM calls the Execute method on the object. For performance reasons, CRM DOES NOT dispose of the object after it completes execution. So CRM caches the object and calls Execute on the same object instance on the next activation of the plug-in. CRM will flush its cache when any properties are changed on the pluginassembly, plugintype, sdkmessageprocessingstep, sdkmessageprocessingstepimage entities for registration. This means that you need to be very careful when defining class-level variables in the plug-in class as multiple threads can execute the code at one time.

     

    http://blogs.msdn.com/b/crm/archive/2008/11/18/member-static-variable-and-thread-safety-in-plug-in-for-crm-4-0.aspx

     

    • Marked as answer by BERKAYA Hedi Thursday, September 2, 2010 2:30 PM
    Tuesday, August 31, 2010 2:05 PM
  • Are you setting class level variables?
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, August 31, 2010 2:24 PM
    Moderator
  • Yes, I have some class level variables
    Tuesday, August 31, 2010 2:38 PM
  • Does one relate to the salesorder such as sales order id.
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, August 31, 2010 3:06 PM
    Moderator
  • yes I have salesorderid as class level variables.
    Tuesday, August 31, 2010 3:11 PM
  • then as the article that you provided states, you should avoid the use of class level variables as multiple threads can call the plugin and may end up using the values stored in class variables set by a previous thread. You should pass your variables as parameters to functions and avoid class scoped variables. Do this and let me know if your problem disappears.
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, August 31, 2010 3:43 PM
    Moderator
  • Yes the problem is resolved
    Thursday, September 2, 2010 2:30 PM
  • Was the class scoped variable holding the salesorder id?
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Thursday, September 2, 2010 2:46 PM
    Moderator