Dynamics CRM, Email, Workflow

Fix: Microsoft.Crm.CrmException: Cannot create the given type without the required parameters.

If you use CRM workflows to create and send notification emails you may come across this error, usually after just having changed the workflow definition in some way:

Microsoft.Crm.CrmException: Cannot create the given type without the required parameters

The full ungodly error message will be something like:

Plugin Trace:
[Microsoft.Crm.Workflow: Microsoft.Crm.Workflow.Activities.EvaluateExpression][EvaluateExpression]
Error Message:
Unhandled Exception: Microsoft.Crm.CrmException: Cannot create the given type without the required parameters.
at Microsoft.Crm.Workflow.Services.ExpressionServiceBase.CreateCrmType(WorkflowPropertyType type, Object[] values)
at Microsoft.Crm.Workflow.Services.ExpressionServiceBase.EvaluateExpression(ExpressionOperator expressionOperator, Object[] parameters, Type targetType)
at Microsoft.Crm.Workflow.Activities.EvaluateExpression.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

When does it happen?

This message has been driving me crazy. Complex workflows that were working perfectly well one minute break after making insignificant changes. At work we have so many workflows sending notifications that even the thought of changing some of them can bring me out in a cold sweat. This is because the only way I knew of to fix them when they break was to rebuild whole branches of quite complex workflows. Not. Funny.

This happened again today and I did a bit more digging. I now have a slightly better understanding of the issue. I don’t know how to fully fix the issue – but I do have a better approach now than rebuilding whole workflows, branches of logic or the email step.

The issue happens when you change the From, To, CC or BCC fields

It’s possible there are are other scenarios where you’ll get this message – but if you’ve just changed say, the recipient list of the email – then there is a very good chance that this is the problem.

How do I fix it?

In all the cases I’ve experimented with, I didn’t need to delete the whole workflow or even the email step. This was the approach I had been using but it turns out its overkill.

Given that the problem is something to do with the workflow engine being unhappy with the From, To, CC, or BCC fields – all you need to do is reset the values in those fields and force a save. The approach I’m currently playing with when making a change is:

  1. Remove all values from the field you are changing. So if you are changing the To list – delete everything from it.
  2. Save the workflow and close it. You might even consider Activating it though I’m not sure if this is necessary
  3. Reopen the workflow and set the field to the intended value
  4. Save and activate

If you clear everything out and save the workflow – then come back and correct it – the issue doesn’t seem to occur.

It’s still not the most awesome user experience but I hope this saves at least someone from destroying their workflow just for the sake of one corrupt field!