Sunday, November 2, 2014

CRM 2013 SP1 - Debugging Custom Workflows

The topic for today is creating and then debugging a custom workflow for CRM 2013 SP1.  Sounds simple enough, right?  If you have done this type of work in the past it should be straightforward:  You make your DLL though Visual Studio, you deploy your DLL, profile the workflow, make a debug-text file from the profiling, then use the plugin registration tool and debug.

There are a few problems though, given the current (6.1.1) SDK.

First, if you're adding plugins through the plugin registration tool don't use version 6.1.1.  If you do, the tool won't detect your workflows so you can't register them nor debug them (if you managed to get your steps in using Visual Studio).  Find a version of 6.1.0 online and use that instead.

Version 6.1:



Version 6.1.1:



Once you've gotten past that hurdle, you can add the step to your solution and start profiling.  You'll hit another snag later though:

Version 6.1.1:



The profiler won't/can't find which plugin/workflow step you're trying to debug.

Version 6.1.0:



And the details of the error:

"Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Could not load file or assembly 'Microsoft.Xrm.Sdk.Workflow, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."


This error basically means that the plugin profiler can't find the Microsoft.Xrm.Sdk.Workflow file.  Personally, I've tried placing the file in the location of my DLL, of the plugin registration tool, even where the debug file is (and even putting everything in the plugin registration folder).  To get around this, add the file to your local GAC (global assembly cache).   In case you're not familiar with this, perform the following steps:

  • Open a command prompt as an administrator.
  • Browse to where gacutil.exe file is on your machine.
    • For Windows 7 on my machine, this is at C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools.
  • Register the Workflow DLL that was used to make your workflow step (which should also be the same DLL in the plugin registration folder.
    • Type gacutil.exe -i <location of the file>


And then you should be all set to debug!  Remember to use version 6.1.0 of the plugin registration tool from the SDK, or hopefully 6.1.2 / 6.2 when they come out.

2 comments:

  1. Thanks a lot... that same error i faced and was hitting my head against the wall to get rid of this. Your blog told me to register the workflow dll in gac and that was it!!

    Thanks a lot. Sunil

    ReplyDelete