Error in WF - InvalidCastException

Apr 21, 2011 at 11:27 AM


I have created a basic workflow that does the following:

Step 1: Calculate "2 business hours" from Lead:CreatedOn
Step 2: Timeout until 2BusinessHours:Result then
Step 2.1: Create Task

Step 1 is processed successfully and Step2 fails immediately thereafter (i.e. it does not even wait for "2 business hours" and then process the remaining statements)
The following error is recieved: "Workflow paused due to error: Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
   at lambda_method(Closure , ActivityContext )
   at Microsoft.VisualBasic.Activities.VisualBasicValue`1.TryGetValue(ActivityContext context, TResult& value)
   at System.Activities.InArgument`1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityContext resolutionContext)
   at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

If however I add an Update Lead:MyCustomDate step in between Steps 1 and 2, and then timeout on the updated field, it works fine

Step 1: Calculate 2 business hours from Lead:CreatedOn
Step 2: Update Lead:MyCustomDate == (Lead:CreatedOn + 2BusinessHours)
Step 3: Timeout until Lead:MyCustomDate then
Step 3.1: Create Task

I have set my CRM Server and CRM User to both US DateTime formats and SouthAfrican DateTime formats and this makes no difference (Initially I thought it might be related to my SouthAfrican DateTime format)

PS. I also noticed that if I add any "breaks" to my business hours calendar in CRM, these are not calculated into the equation.


Start @ 08h00 End @ 12h00 (Work Hours)
Start @ 12h00 End @ 13h00 (Lunch) ... This is still considered as working hours ...
Start @ 13h00 End @ 17h00 (Work Hours)

I would be most greatful for any assistance in resolving the above mention error.

Apr 29, 2011 at 4:47 PM

Ok... that is pretty interesting, and I will have to look into it.  On a side note, which version are you using the CRM 4 or CRM 2011 (not that it makes a difference) - I'm just not sure how much longer I will do upkeep on both versions.  Pretty soon I will stop updating the CRM 4 library and release plugins for the soundex and metaphone codification for 2011 as part of the library.

May 3, 2011 at 12:04 PM

I am using CRM 2011 RTM, and I have not upgraded tp UR1 yet. 
I also made sure that I downloaded the latest dll from the downloads page.