I have created plugin and had to debug my C# code. Setting up debug process is complex. Microsoft offers good instructions but there were some things that I just had to figure out myself. I will tell you all my workarounds and tips how to get your plugin debugged.

Challenge is, that is your code goes to error – you cannot debug your code since the Profiler don’t catch the execution. In for these cases you need to write a lot of trace. It really felt like old school PHP debugging when there is no possibility to actually debug the code.

But let’s first go trough what is the process to debug your code. Here is my description shortly:

I will put these steps here just to get you understand what king of process the debugging

1. Install plugin assembly and create a step
2. Install Profiler (this takes a lot of time)
3. Start profiling (this takes a bit less time after click )

Installing assembly, profiler and start profiling
Installing assembly, profiler and start profiling

4. Execute tasks meaning go to UI and click what starts the plugin
5. Select Step in Profiler, click Start Debugging (check MS instructions programs for debugging for more detailed screenshots, note also that after first debugging you can just use Reattach command)
6. Choose task meaning datetime when your plugin executed
7. Set Visual Studio in debug mode with attach to Plugin Registration Tool process
8. Press start executing in Profiler
9. Debug your code in Visual Studio

Okay, I found the problem – then I stopped debugging, fixed my code and want to try again. Then I need to…

1. Click Stop Profiling in Plugin Registration tool (I noticed, that if I just update new assembly, the profiling usually don’t catch executions in the UI anymore and then I need to uninstall and reinstall the Profiler)

2. In Plugin Registration tool update the assembly, select the dll (be sure you have build the solution / project in Visual Studio)

Updating assembly in Plugin Registration Tool
Updating assembly in Plugin Registration Tool

Select built assembly from Debug folder
Select built assembly from Debug folder

3. Click Start Profiling in Plugin Registration tool again
4. Execute tasks meaning go to UI and click what starts the plugin
5. Select Step in Profiler, click Start Debugging
6. Choose task meaning datetime when your plugin executed
7. Set Visual Studio in debug mode with attach to Plugin Registration Tool process
8. Press start executing in Profiler
9. Debug your code in Visual Studio

But there are so many events and time, since my plugin updates child events the same time, which to choose?

My code updates other rows, I set break point there where I catch the main event after checking the main event. This way it is very fast to find the execution I want to debug, event though Profiler gives multiple execution times.

Set break point when I catch the main event
Set break point when I catch the main event

I cannot get new time events in debugging mode, what to do?

Then you need to clink Uninstall Profiler and after that click Install Profiler. Between these might help update the assembly, if this does not help.

Resinstall Profiler
Resinstall Profiler

Debugging a plugin is a bit complex procedure. You need to ensure, that the latest version of the assembly is installed and Profiler is started after that. Then you could catch your executions in UI, if your plugin does not catch exceptions.

Remember that if some other out-of-the-box plugin catches exception, then you need to be able to use tracing to see where your plugin crashed, even though it is not your plugin code crashing. In my case this happened, since I had parent event, which updates child events in the same table and I need manually check in the code that it is main event. Both will trigger event table Update event and filtering offers only check which column is changed, not offering possibility to check the value of the column.

Creating a step for plugin in Plugin Registration Tool
Creating a step for plugin in Plugin Registration Tool

You see your traces with Advanced Search, remember to turn on plugin tracing in Dynamics 365 settings.