DYNAMICS 365 HOW TO DEBUG PLUGINS USING REMOTE DEBUGGER

In another post, we saw how to debug a plugin using Profiler and highlighted a downside of this method which will not give you a real-time state of the Dynamics 365 database you are working on.

However, in this post, I will show you how to debug a plugin in real-time of the execution of the plugin itself using the Visual Studio remote debugger tool.
This method will only work for On-premises environments since you should install and run the tool on the CRM server.

The below steps will teach you how to debug the plugins
  1. First things first, you have to download the remote debugger tool using this link based on the Visual Studio version you are working with
  2. Once the download is done, copy the installer on the CRM server and double click to install it
  3. When the installation is done, right click > Run as administrator
  4. In the remote debugger popup that is opened, you can notice the server name with a port number. Copy these information because they will be used in the next step within the Visual Studio
    debug plugins

  5. In Visual Studio, build your plugin project and go to the Debug folder found under the project folder
  6. Copy the .pdb file of your plugin and paste it in the following folder of the CRM server C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly
  7. Register your plugin using the Plugin Registration Tool so the latest changes are applied to the CRM
  8. Return to Visual Studio and from the menu select Debug > Attach to Process
  9. In the pop up window, for the Connection target option, enter the server name and port number you copied earlier from the remote debugger
  10. Select the checkbox Show processes from all users and click Refresh button. Scroll down to the end and select the process w3wp.exe and click Attach
    debug plugins 2

  11. Finally, set a breakpoint on the line of code where you want the debugger to stop and go to CRM and execute the action that will trigger the plugin to be executed... Few seconds and the debugger will stop on your breakpoint
    debug plugins 3

Bonus Tips:
  • Work with the .dll and .pdb files generated from the same build action of the plugin project. Use the .dll in the Plugin Registration Tool and copy the .pdb to the CRM server
  • In the attach process pop up window, select all the w3wp.exe in case of many processes
  • You can debug the asynchronous plugin by attaching to the processes named CrmAsyncService.exe


Hope This Helps!

Comments

Post a Comment

Popular posts from this blog

DYNAMICS 365 HOW TO HIDE RECENT RECORDS FOR LOOKUP FIELD IN UCI

SEARCH BY GUID IN DYNAMICS 365

SAVE FORM IN DYNAMICS 365 JAVASCRIPT