Issues in debugging custom workflow assemblies

Three months ago, I wrote a post about profiling workflows with custom activity step -> Debugging custom workflow assemblies

There were couple of comments in the post, about it not working as expected due to

  1. Different version of CRM and/or
  2. Different version of Plugin Registration tool

I will now give you the steps to get this working.

  1. Install LINQPad -> https://www.linqpad.net
  2. Install CRM Driver for LINQPad -> https://crmlinqpad.codeplex.com/
  3. After creating a connection to your CRM instance, run this LINQ query
    XNamespace mxswa = "{clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}";
    var query = from w in WorkflowSet.AsEnumerable()
    where
    w.Name == "[YOUR WORKFLOW NAME WITH CUSTOM STEP]" &&
    w.FormattedValues["type"] == "Definition"
    && w.IsCrmUIWorkflow.GetValueOrDefault()
    orderby w.ModifiedOn descending
    select new {
    w.Id,
    w.Name,
    WorkflowVersion = XElement.Parse(w.Xaml).Attributes().FirstOrDefault(a => a.Name.LocalName == "mxswa").Value.Split(';')[1],
    CustomSteps = from a in XElement.Parse(w.Xaml).Descendants($"{mxswa}ActivityReference")
    			   where !a.Attribute("AssemblyQualifiedName").Value.Contains("Microsoft.Crm")
    			  select new {
    			  CustomStepName = a.Attribute("DisplayName").Value,
    			  AssemblyName = a.Attribute("AssemblyQualifiedName").Value,
    			  HasArguments = a.Descendants($"{mxswa}ActivityReference.Arguments").Any()}
    };
    query.Where(c=>c.CustomSteps.Any()).Dump();
    
  4. You’ll get something like this. Note that the workflow in my case is “Blank Workflow with Custom Step”. Change this to the one you are trying to profile.Query

Issue 1: Cannot see the workflow step.

Blank Step

If you cannot see the workflow step, that means that there is a mismatch between the Microsoft.Xrm.Sdk.Workflow.dll version and/or your custom workflow step version. Go the folder with the Plugin Registration tool and check the version of the Microsoft.Xrm.Sdk.Workflow.dll version. The important thing is if the major version or minor version of the Microsoft.Xrm.Sdk.Workflow.dll assembly in Plugin Registration tool folder, is different from the one in the Workflow XAML, you will not see the step displayed.

CRM 2016 Plugin Reg Tool
CRM 2016 Plugin Registration Tool
CRM 2016 Update 1 Plugin Reg Tool.png
CRM 2016 Update 1 Plugin Registration Tool

Compare this with the results of the LINQ query and confirm that the major version and minor version match. Do this same for your custom workflow assembly as well.

Issue 2: NullReferenceException

There is a bug in the Plugin Registration Tool, that doesn’t allow you to profile workflow steps, that doesn’t have any argument. If you try to do this, you will get this exception.

Null Reference.png

The workaround for this is to add a dummy argument, to keep the plugin profiler happy.

Workflow

Hope this helps with your debugging efforts.

Advertisements

9 thoughts on “Issues in debugging custom workflow assemblies

  1. hi i have a problem, where my profiled workflow is running into an infinite wait status when triggered.
    Unprofiled workflow is running fine and i can’t find any error messages. Did you come across this one yet ?

  2. I have a problem where my profiled workflow is running into infinite wait after triggering.
    Unprofiled one is running fine and i cant find any error messages. Did you come across this one yet ?

    • You profile the workflow step and run the workflow with suffix profiled. This workflow doesn’t complete and waits indefinitely. Is this the situation? Can you please post it in the forums so that you can share some screenshots?

      • Thanks mate,
        I am currently stuck on this
        The following errors were encountered while processing the workflow tree:
        ‘DynamicActivity’: The private implementation of activity ‘1: DynamicActivity’ has the following validation error: Compiler error(s) encountered processing expression “DirectCast(CustomActivityStep1: another dummy text_1_converted, System.String)”.
        Syntax error in cast operator; two arguments separated by comma are required.

        I have checked the link above you have suggested, but that didn’t helped.
        Do you see anything obviously wrong in this code ?
        I am struggling for a while….

        public class WorkflowClassTest : CodeActivity
        {
        [Input(“Dummy Argument”), RequiredArgument]
        [Default(“Guid”)]

        public InArgument DummyArgument { get; set; }

        [Input(“Dummy Argument 2”), RequiredArgument]
        [Default(“EntityLogicalName”)]

        public InArgument DummyArgument2 { get; set; }

        [Output(“Fetch Output”), RequiredArgument]

        public OutArgument FetchOutput { get; set; }

        protected override void Execute(CodeActivityContext executionContext)
        {
        ITracingService tracer = executionContext.GetExtension();
        IWorkflowContext context = executionContext.GetExtension();
        IOrganizationServiceFactory serviceFactory = executionContext.GetExtension();
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

        try
        {
        //DummyArgument = “abc”;

        }
        catch (Exception e)
        {
        throw new InvalidPluginExecutionException(e.Message);
        }
        }
        }

  3. ok found the solution, whatever input variable you have in the profiled wf, add any dummy value to it save and rerun.. adding default value was not working for me.
    Cheers
    Bharat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s