Plugin Registration tool can be used to debug not just plugin assemblies, but also custom workflow assemblies. I am not sure how well known this feature is, as I could not find any documentation about this in msdn.
Prerequisite
Use the correct version of Plugin Registration tool for your organisation. I could not use Plugin Registration tool that came along with CRM SDK 7.1.1, to debug a workflow assembly running in CRM 2015 Update 0.1 (7.0.1). I could however use Plugin Registration tool 8.0.0.7198 to debug workflow assembly running in CRMOnline 2016 (8.0.1.79). So, it seems the major version and minor version have to match to enable workflow assembly debugging.
After installing the profile, select the plugin profile node. You will now see a new button called “Profile Workflow”
Next, choose the CRM workflow which contains the custom workflow assembly. If the workflow has multiple custom workflow assembly steps, you will see each of these in this screen. You can choose the assembly to profile. It is best to choose “Persist to Entity” option, as you won’t see the exception when it is thrown by the workflow.
Once you click OK, a clone of the workflow will be created. It will have “(Profiled)” in the end. Your original workflow will now be in “Draft” state.
Now execute the profiled workflow manually. Confirm that the workflow has finished running.
Once the workflow has completed running, you can now use the serialised profile to debug the workflow assembly. After you click the “Replay Plugin Execution” button you will see this screen, which will help you to select the correct profile record.
I ran the workflow manually only once and hence there is only one profile row. If the workflow ran multiple times, you will see multiple rows. After you click select, you’ll then have to choose the correct workflow assembly that matches this profile.
Now attach the Visual Studio Debugger to the Plugin Registration Tool. Now is also a good time to put couple of breakpoints in the workflow assembly code in Visual Studio. Once you click “Start Execution”, the control should now be transferred to Visual Studio to facilitate debugging.
The behaviour is exactly same as plugin debugging. You can step though the code, understand the root cause of any weird behaviour and resolve it. Once you complete the execution, you will see the trace logs in the profiler.
One more thing: You can use this exact same process to debug an Action which has a custom assembly. Here is how the profile looks when an action with custom workflow assembly is profiled.
Things to note:
- When a workflow step is profiled, the workflow assembly containing this activity is cloned and registered as a profiled workflow assembly. It is this assembly that is used in the workflow that has the name ending with “(Profiled)”
- Even though you can see the workflow being profiled, stopping the workflow profile using the Plugin Registration tool seems impossible. You can see what is being profiled.
- In order to stop profiling, you’ll have to
- Unpublish and delete the workflow/action that ends with “(Profiled)“
- Delete the weirdly named assembly (all guid name) from the “Default Solution“. This will be under the “Plugin Assemblies” node
I hope this technique will help you to debug custom workflow assemblies quite easily. Happy debugging.
EDIT (01/07/2016): Please refer Issues in debugging custom workflow assemblies where I address the issues in the comment.
Hi, While choosing the “Persist to entity” radio button and click the “OK” button, I am getting the below error (online version CRM 2015)
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: workflowSteps
at PluginProfiler.Library.ProfilerManagementUtility.EnableWorkflow(CrmServiceClient service, String overrideKeyFileName, Guid workflowId, Boolean persistToEntity, String persistenceSessionKey, Boolean includeSecureInformation, Boolean isContextReplay, CustomActivityStep[] workflowSteps)
at Microsoft.Crm.Tools.PluginRegistration.ProfilerSettingsViewModel.btnOk_Click()
It think it is a bug in the old versions of Plugin Registration tool, where you can click OK without selecting the workflow step. Did you select the workflow step (see screenshot 2) before clicking the OK button? You also will see the workflow step if you use the correct plugin registration tool version applicable to your CRM version.
Hi, Thanks for your reply. I have used ur code and steps . I have selected steps as per ur screen shot. Online version 2015. SDK version also 2015.
While clicking the OK, I got the above error.
I have tried last 2 days. But no improvement.
Kindly provide suggestions
I have not encountered this error if I selected the workflow step. But, I didn’t check across all CRM versions and plugin reg tool versions. Can you please post this in the http://community.dynamics.com/crm/, so that someone who has encountered similar issue will be able to assist?
I have tried to debug my WFActivity with CRM 2015 On-premise (Database/none) and CRM 2016 Online (Sandbox) and I get the same error… Object reference not set to an instance of an object.
I have tried with Persist entity or Exception options with the same result error.
I haven’t tried this in CRM2015, as I don’t have the correct version of the Plugin Registration tool. I have tried this only in CRMOnline and it was working at the time of the post. I will check this once again in CRMOnline today, and see whether this is a bug that manifests in CRM2015 or the older version of the Plugin Registration Tool.
[…] Three months ago, I wrote a post about profiling workflows with custom activity step ->Â Debugging custom workflow assemblies […]
I finally got the time to do this properly. Please refer https://dreamingincrm.com/2016/07/01/issues-in-debugging-custom-workflow-assemblies/
[…] Three months ago, I wrote a post about profiling workflows with custom activity step ->Â Debugging custom workflow assemblies […]
[…] am able to debug my workflow. For debugging custom activity workflow please refer below links https://dreamingincrm.com/2016/02/26/debugging-custom-workflow-assemblies/ https://dreamingincrm.com/2016/07/01/issues-in-debugging-custom-workflow-assemblies/ Hope […]
[…] am able to debug my workflow. For debugging custom activity workflow please refer below links https://dreamingincrm.com/2016/02/26/debugging-custom-workflow-assemblies/ https://dreamingincrm.com/2016/07/01/issues-in-debugging-custom-workflow-assemblies/ Hope […]
Hi, I am having Dyanmics CRM Online 2016 instance. I tried to perform the same steps you have mentioned but getting following error while click OK:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at PluginProfiler.Library.WorkflowXamlUtility.InstrumentStep(XmlNode activityNode, XmlNamespaceManager ns, InstrumentedStepConfiguration step, String workflowAssemblyName)
at PluginProfiler.Library.WorkflowXamlUtility.InstrumentXaml(CrmServiceClient service, String xaml, IList`1 steps)
at PluginProfiler.Library.ProfilerManagementUtility.EnableWorkflow(CrmServiceClient service, String overrideKeyFileName, Guid workflowId, Boolean persistToEntity, String persistenceSessionKey, Boolean includeSecureInformation, Boolean isContextReplay, CustomActivityStep[] workflowSteps)
at Microsoft.Crm.Tools.PluginRegistration.CommonControls.ProfilerSettingsViewModel.btnOk_Click()
Did you refer my other post on troubleshooting -> https://dreamingincrm.com/2016/07/01/issues-in-debugging-custom-workflow-assemblies/
You most likely don’t have an input parameter. Due to a bug in plugin reg tool, you’ll have to add an input param. Let me know if it is not the case.
I also tried adding the input parameter as you have suggested in the other blog..
but its still giving the same error for me!!
Did you unregister and re-register the assembly and delete and readd and step? Try that as you cant restart async service in crmonline. The error message seems to be same. Post it in the forums, if it still doesn’t work.
HI..
So, I tryied to follow this step, but when I clicked on OK button on Profile Settings I had this error:
Unhandled Exception: System.InvalidOperationException: Unable to generate a default key to use to sign the workflow shim assembly. Create a key (using sn -k) and store it in “C:\Program Files (x86)\SDK\Tools\PluginRegistration\PluginProfiler.DefaultWorkflowAssembly.snk”.
You know why? Someone can help me??
I’m using CRM Online
I haven’t encountered this error before. Try posting this in the forum -> community.dynamics.com/crm/