Problem

If you encounter the below error when in Dynamics CRM while trying to profile a custom workflow plugin using the CRM Plugin Registration utility

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()
System.NullReferenceException CRM Plugin Registration Screenshot

Solution

This is a known bug that has existed in the CRM Profiler for quite some time. It assumes that your custom workflow will have an input argument, if it doesn’t then you’ll see that nasty error.

The solution is to add a fake argument to workaround the issue.

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyOrg.CRM.MyPlugin
{
    public class DoStuff : CodeActivity
    {
        // Fake argument to prevent CRM Profiler from crashing
        [Input("Fake Argument for Profiler")]
        [Default("Fake Argument for Profiler")]
        public InArgument MyDummyArgument { get; set; }
        //

        protected override void Execute(CodeActivityContext activityContext)
        {
            var serviceFactory = activityContext.GetExtension();
            var workflowContext = activityContext.GetExtension();
            ...
Shane Bartholomeusz