Microsoft Dynamics CRM 2011

Microsoft Dynamics CRM 2011

Tuesday, December 24, 2013

How to debug a CRM 2011 Custom Plugin / Workflow

by Carmel Schvartzman

  1. In this walkthrough we will learn Step - By - Step How to debug a custom  Plugin / Workflow in Dynamics CRM 2011. Once you have developed your custom workflow, you deploy the assembly containing the plugin in the CRM web server, and register it with the Plugin Registration Tool of the CRM 2011 SDK.
  2. The problem is, every time you change the code, and recompile the assembly, you must redeploy it and the process of debugging-compiling-deploying-registering is very time-consumer and this cycle restarts for every bug and every update you may want to do.
  3. The best and quickest way of debugging-redeploying  your plugin is inside the CRM server itself. If you upgrade your code from inside the CRM web server, the process of debug and redeploy it will be far more quicker. You can also perform the testings against a test Organization.
  4. First, check whether or not Visual Studio 2010-2012 is installed in the CRM web server. If it doesn't, install it.
  5. Next, copy the workflow solution to the CRM server, or else develop entirely your  Plugin from the Visual Studio in the CRM server.
  6. Provided you have already built your workflow project, you must deploy it in the CRM server. You copy the assembly from the BIN folder of your project, to the special folder where CRM expects the plugins to be ( Microsoft Dynamics Crm\Server\Bin\Assemply ). Then, open the Plugin Registration Tool, and select "Register New Assembly":
  7. How to debug a CRM 2011 Custom Plugin / Workflow
  8. Specify the assembly location:
  9. Select the "Database" option:
  10. Now that your plugin has been registered, you can debug it this way: switch to the workflow project opened in the Visual Studio installed on the CRM web server:
  11. On the "Debug" tab, select "Attach to Process":
  12. Now select the two "CrmAsynchService.exe" which are running on the CRM server. Those are the services which take care of the plugins, workflows, and every asynchronic processes being run on the CRM 2011:
  13. Press the "Attach" for each one of the processes:
  14. Now debug your workflow at your ease. Open your CRM account and call the workflow which calls your custom plugin/workflow. Wait some seconds (it's an asynchronic process so CRM will decide by its own when to run your plugin) and you'll see that the breakpoints you have set on your code will be reached.
  15. Let's say that you've found a bug or you need to upgrade the code. You compile it and next you must redeploy the assembly and update the registration of the plugin, and debug again.  Therefore, open the BIN folder of your workflow project, and copy the .dll:
  16. Now open the folder where are stored the CRM custom plugins ( Microsoft Dynamics Crm\Server\Bin\Assemply ):
  17. Paste there the assembly. Next, open the Plugin Registration Tool, select your assembly and press "Update":
  18. Specify the location of the assembly to update:
  19. Finally click the button "Update Selected Plugins":



    And now you can debug again your plugin and see how the breakpoints are reached by the runtime.


    That's all...Enjoy Dynamics CRM


    כתב: כרמל שוורצמן