Synch Plugin & Asynch Plugin & the SharedVaribales RRS feed

  • Question

  • Hi All,

    I have a plugin that run in a Pre-Stage using the Synch Mode, and a second plugin that run in the Post-Stage using the Asynch Mode for the same entity.

    Can those two plugin share a variables using the context.SharedVaribales?


    Thanks for Help

    Friday, June 4, 2010 2:20 PM


All replies

  • Since the Async plugin would be handled by the Async service, I'm fairly certain that you can not use SharedVariables in this situation.
    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/
    Friday, June 4, 2010 2:26 PM
  • As said  above, No, i don't think  it will be possible, If you want to share some data, u can use the Pre-Stage of Async to write to some data source(may be File, MS CRM Entity, Database) and then in  Async Operation  you can read it from  the respective data source.
    Muhammad Ali Khan
    Friday, June 4, 2010 2:30 PM
  • have you an idea or a work arround to share variable between Synch and Asynch plugin.

    Friday, June 4, 2010 2:32 PM
  • I think  the one way is  to use some other datastore e.g. File, MS CRM Entity(same or different), Database. but i don't  think you can use SharedVariables from context object to share the data.
    Muhammad Ali Khan
    Friday, June 4, 2010 2:38 PM
  • Hi Muhammad,

    what do you think if a create a static class with a static proprties, and this class will be created in the Pre-Stage plugin Synch Mode, after that the Post-Stage will get the properties using the static property without the SharedVariables? 

    Friday, June 4, 2010 2:38 PM
  • No Muhammad, in my case the data that i would share its a connexion object to a WCF Service, I want to connecte to the service and passing the object service client to the Post-Stage Asynch.
    Friday, June 4, 2010 2:40 PM
  • Hi,

    Sharing the connection object is not a good idea i think, you can create it again in your Async Service. i think you should re-consider sharing the  connection object to wcf service as it can be created again in your async service

    Muhammad Ali Khan
    • Marked as answer by Jim Glass Jr Monday, June 7, 2010 5:43 PM
    • Unmarked as answer by Jim Glass Jr Monday, June 7, 2010 5:43 PM
    Friday, June 4, 2010 3:34 PM
  • I'm pretty sure all the above answers are wrong. There should be no problem using SharedVariables between synchronous and asynchronous plugins, as the context information is persisted in the MSCRM database for the asynchronous plugins
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Saturday, June 5, 2010 5:14 PM
  • It shouldn't be too difficult to just try it anyway. Just write two simple test plugins to see if it works, f.i. put a string "test" in the SharedVariables in a pre stage plugin and see if it still exists in a post stage async plugin.
    Saturday, June 5, 2010 6:30 PM
  • Hi David,

    even we can shared variables between Synch and Asynch Mode, for my case, the variable its a service wcf client object, so i can not garantie that the object stay alive stil and keep the connection until the Asynch plugin will be fired. 

    Monday, June 7, 2010 5:22 PM
  • I think the general point is that you can happily use SharedVariables between synchronous and asynchronous contexts for any data that can be serialised. If you're saying that the wcf client cannot be serialised (which sounds likely), then you'd have to recreate the instance, but I'd exepct any data you'd need to recreate it could be stored in SharedVariables
    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
    Tuesday, June 8, 2010 8:23 AM
  • Hi David,

    As you said we can share variable between Async and Sync pluguins

    Could you please how we can do that ?

    Or have an idea about that

    Thanks for replying

    Wednesday, June 9, 2010 10:12 AM
  • Hi,

    Only types that are XML serializable should be placed in SharedVariables. All types derived from BusinessEntity are XML serializable.

    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Wednesday, June 9, 2010 2:07 PM
  • Thanks Ranjitsingh R for replying

    I know how to seralize object to xml  file but i don't know how to serialize the object in sharedVariables

    Could please tell me how to serialize the object in sharedVariables


    Wednesday, June 9, 2010 3:28 PM
  • You must not serialize the object explicitly yourself, but objects that are put in the SharedVariables should be serializable, i.e. they must have the [Serializable()] attribute in their class definition. Just like storing objects in the Viewstate of an ASP.NET form.
    Wednesday, June 9, 2010 7:25 PM