Update: I was able to reproduce this problem, and have reported it to Microsoft as a bug for resolution. Please vote for it as an important fix so it can be resolved in the next Rollup Update!

Let me tell you a little story about a bug…

I had just completed a complex workflow process in Microsoft Dynamics CRM 2011. The workflow checks a number of conditions and then sends one (of any numerous) email templates to a distribution group filled with dynamic fields from the primary and related entities. It was painstaking created, tested, and modified several times until the conditions and templates were perfect. Then, I simply updated the “To” fields to make it live… But upon the first execution, no email went out and I got the error:

An error has occurred. Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization’s Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.

No problem, I thought, I’ll just go back in and mess with the Send Email steps that are failing to figure out what the problem is. But when I went to click the “View Properties” or “Edit Properties” to see/change the created email record, I got a CRM unhandled exception with the following stack trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
at Microsoft.Crm.Application.Platform.WorkflowLibrary.WorkflowAdapter.GetEntityProperty( ExpressionBase propertyExpression)
at Microsoft.Crm.Application.Platform.WorkflowLibrary.WorkflowAdapter. GetEntityPropertyForProperty(PropertySpecification property, String uiXmlName, String& slugInfo)
at Microsoft.Crm.Application.Platform.WorkflowLibrary.WorkflowAdapter.PopulateEntityProperties( EntitySpecification entitySpec, EntityBase entity, String uiXmlName)
at Microsoft.Crm.Web.Sfa.EntityForm.get_FormEntity()
at Microsoft.Crm.Web.Sfa.EntityForm.ConfigurePage()
at Microsoft.Crm.Application.Controls.AppUIPage.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

[HttpUnhandledException: Exception of type ‘System.Web.HttpUnhandledException’ was thrown.]
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication. IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Now I was stuck–I didn’t want to recreate the entire workflow manually and painstakingly test over and over again manually. No one had ever heard of this problem, and I couldn’t find anything online about how to solve it.

To solve it, I exported the workflow and dug through the XAML to find the root of the problem. When I created the Send Email steps in my workflow, I had filled out the “To” and “CC” fields with User accounts for testing purposes. When I modified it to make it “live,” I changed the “To” entity record (to the live distribution list Contact record) and completely cleared the “CC” field. However, for some reason CRM still had a pointer doing and entity record lookup for the “CC” field, and it was failing to look it up because there was no record indicated (the field was blank).

I noticed in the XAML there was a SetEntityProperty in the Send Email sequences that shouldn’t be there for a blank “CC” field. Something like this:

<mxswa:SetEntityProperty Attribute=”cc” Entity=”[CreatedEntities("SendEmailStep1_localParameter#Temp")]” EntityName=”email” Value=”[SendEmailStep1_1]”>
<mxswa:SetEntityProperty.TargetType>
<InArgument x:TypeArguments=”s:Type”>
<mxswa:ReferenceLiteral x:TypeArguments=”s:Type” Value=”mxs:EntityCollection” />
</InArgument>
</mxswa:SetEntityProperty.TargetType>
</mxswa:SetEntityProperty>

The ActivityReference for SendEmailStep1_1, however, contained a weird stub for an empty PartyList. This was causing the Index out of Range lookup error, which was crashing CRM:

<mxswa:ActivityReference AssemblyQualifiedName=”Microsoft.Crm.Workflow.Activities.EvaluateExpression, Microsoft.Crm.Workflow, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ DisplayName=”EvaluateExpression”>
<mxswa:ActivityReference.Arguments>
<InArgument x:TypeArguments=”x:String” x:Key=”ExpressionOperator”>CreateCrmType</InArgument>
<InArgument x:TypeArguments=”s:Object[]” x:Key=”Parameters”>[New Object() { Microsoft.Xrm.Sdk.Workflow.WorkflowPropertyType.PartyList }]</InArgument>
<InArgument x:TypeArguments=”s:Type” x:Key=”TargetType”>
<mxswa:ReferenceLiteral x:TypeArguments=”s:Type” Value=”mxs:EntityCollection” />
</InArgument>
<OutArgument x:TypeArguments=”x:Object” x:Key=”Result”>[SendEmailStep1_1]</OutArgument>
</mxswa:ActivityReference.Arguments>
</mxswa:ActivityReference>

The solution was to remove the offending references to the “CC” field and associated activities. Problem solved! And that’s the last time I use the “CC” field for testing purposes without backing up my workflows first!!!

eImagine is an Indianapolis-area leader in Microsoft Dynamics CRM. Whether you’re looking for an out-of-the-box CRM implementation, and highly customized solution, or an XRM-based extended CRM product, we’re the local company with the expert staff to get it done! Learn about our CRM experience.

Need to test the height of this box....

Social Wall