Plugins Development in Dynamics 365 CRM | Part 4 – Debugging the plugin

Given that you are coming here from the Part 3: Plugins Development in Dynamics 365 CRM | Part 3 – Adding Logic

Let’s see how we can debug the plugin in case of Exceptions / issues!

Profiling

Now, you’ll need to start Debugging in the Plugin Registration tool

  1. In the Plugin Registration Tool, if a Profiler solution was never installed, you will find this button that says Install Profiler.

  2. It’ll begin installing the Profiler and it takes a few minutes until this is completed.


    Once done, you’ll see this message.

  3. One this is done, you’ll see Uninstall Profiler button all the while.
  4. Now, you need to select the Plugin step and then click on Start Profiling.

  5. Once started, the Plugin step will look like this. The step will have “(Profiled)” mentioned.


  6. Now that you have started profiling the plugin step. You’ll need to “perform the operation” in Dynamics 365 CRM. In this case, updating the Group Code field and clicking on Save.

  7. This will not throw the Exception since the method we chose above was Persist to Entity. And the system will just save the record [But of course, the plugin code was not executed since it throws an error]
  8. Next, you can navigate to Plug-in Profiles in Settings

  9. Make sure the Plug-in and custom workflow activity tracking is turned to All in System Settings.


    Else, you’ll see this error on navigating to the Plug-in Profiles section in Settings.


  10. Next, you’ll find the record which was captured when we tried to replicate the scenario to capture the issue.

  11. Now, when you open this record, you’ll need to expand the Serialized Profile section and copy all the content into a Notepad file.

  12. For example, I’m naming my file as error.txt. Remember where you stored this file.


    Now, let’s Debug the plugin!

Debugging

Now, in order to start debugging the plugin, you’ll need to first, stop the Profiling which we started to capture the logs –

  1. Click on Stop Profiling.

  2. Once stopped, click on the Step, then on Debug to open the Dialog box as shown below.


    It’ll open this dialog. Click on the three dots for Profile field.


  3. Select the text file which was saved. It’ll appear if the text file was correctly rendered.
    Then, click on the three dots in Assembly Location. This will accept the .dll file of the plugin

  4. Once you select the DLL, it’ll detect the Plugin and it’ll be show as below.

  5. Don’t click on Start Execution yet!! Go to Visual Studio and open Attach to Process.
    Shortcut for that is Alt + D [pause for a bit], then press [P].
    Find Plugin Registration Tool and then click on Attach.

  6. Once you click on Attach, the VS will be in Debug mode with the Plugin Registration Tool and you can now set the breakpoint at appropriate location in order to capture the debug. Ideally, this should be early on in the plugin to identify the issue step by step.

  7. Now, you can go back to the Plugin Registration Tool and click on Start Execution.

  8. Once it starts, the breakpoint will be hit and you can then take it forward like any C# program debugging using F10, F11, F5 etc.

  9. Let’s assume the exception was hit correctly where we anticipated it to be hit.
    You’ll catch the exception and fix the code.
    [I had purposely commented in earlier posts for this scenario]

  10. Now, I fix the code. Rebuild and Re-deploy the plugin

  11. And as a result, when I perform the operation again, the plugin works and the child records are updated.
    So, I’ll make a change on the Account record.


    And if I check the Contact, the same will have been updated there as well. This indicates that our intended functionality was successfully implemented.


Hope this series was helpful in getting you an understand of how you can write plugins as a newbie. This is just scratching the surface and one of the early ways to write plugins.
I’ll further extend this series in the future to add best practices and some tools in the marketplace to help you write plugins faster and better!

Hope this was helpful! Here are some more Dynamics 365 posts which you might be interested in –

  1. Dynamics 365 Storage Utilization | Dataverse Storage | Power Platform Admin Center
  2. Use Hierarchy in Roll Up Fields in Dynamics 365 CRM
  3. Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
  4. Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
  5. Dynamics 365 App For Outlook missing on SiteMap in CRM? Use shortcut link [Quick Tip]
  6. Import lookup referencing records together in Dynamics 365 CRM | [Linking related entity data during Excel Import]
  7. Mailbox Alerts Hide/Show behavior in Dynamics 365 CRM
  8. Excel Importing Notes (Annotation) entity in Dynamics 365 CRM
  9. Enable/Disable the need to Approve Email for Mailboxes in Dynamics 365 CRM CE
  10. Call Azure Function from Dynamics 365 CRM using Webhooks
  11. Show Ribbon button only on record selection in Dynamics CRM
  12. Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM

Thank you!!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.