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!
Now, you’ll need to start Debugging in the Plugin Registration tool
- In the Plugin Registration Tool, if a Profiler solution was never installed, you will find this button that says Install Profiler.
- It’ll begin installing the Profiler and it takes a few minutes until this is completed.
Once done, you’ll see this message.
- One this is done, you’ll see Uninstall Profiler button all the while.
- Now, you need to select the Plugin step and then click on Start Profiling.
- Once started, the Plugin step will look like this. The step will have “(Profiled)” mentioned.
- 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.
- 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]
- Next, you can navigate to Plug-in Profiles in Settings
- 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.
- Next, you’ll find the record which was captured when we tried to replicate the scenario to capture the issue.
- Now, when you open this record, you’ll need to expand the Serialized Profile section and copy all the content into a Notepad file.
- For example, I’m naming my file as error.txt. Remember where you stored this file.
Now, let’s Debug the plugin!
Now, in order to start debugging the plugin, you’ll need to first, stop the Profiling which we started to capture the logs –
- Click on Stop Profiling.
- 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.
- 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
- Once you select the DLL, it’ll detect the Plugin and it’ll be show as below.
- 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.
- 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.
- Now, you can go back to the Plugin Registration Tool and click on Start Execution.
- 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.
- 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]
- Now, I fix the code. Rebuild and Re-deploy the plugin
- 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 –
- Dynamics 365 Storage Utilization | Dataverse Storage | Power Platform Admin Center
- Use Hierarchy in Roll Up Fields in Dynamics 365 CRM
- Filter records in a View owned by a Team you are a member of | Dynamics 365 CRM
- Get GUID of the current View in Dynamics 365 CRM JS from ribbon button | Ribbon Workbench
- Dynamics 365 App For Outlook missing on SiteMap in CRM? Use shortcut link [Quick Tip]
- Import lookup referencing records together in Dynamics 365 CRM | [Linking related entity data during Excel Import]
- Mailbox Alerts Hide/Show behavior in Dynamics 365 CRM
- Excel Importing Notes (Annotation) entity in Dynamics 365 CRM
- Enable/Disable the need to Approve Email for Mailboxes in Dynamics 365 CRM CE
- Call Azure Function from Dynamics 365 CRM using Webhooks
- Show Ribbon button only on record selection in Dynamics CRM
- Accessing multiple occurrences of a field in Business Process Flow using JS in D365 CRM