Pageflow crash when using a 'mixed' flow

Topics: Web Client Software Factory, User Forum
May 5, 2007 at 11:06 PM

It is perfectly Legal to create a workflow containing both ‘pagestates’ and ‘eventdriven activities’.
If such a mixed flow gets persisted, there is a crash upon subsequent reloading of the state.
The reason is a typecast to PageState using the () operator in:

PageState Microsoft.Practices.PageFlow.WorkflowFoundation.WorkflowFoundationPageFlowDefinition.GetActivityByUrl(string rawUrl)
return (PageState)_definition.Activities.Find(new Predicate<Activity>(delegate(Activity activity)
return string.Compare(((PageState)activity).Url, rawUrl, true, CultureInfo.CurrentCulture) == 0;

As the flow contains also eventdriven activities this cast will crach as soon as Find() encounters one in _definition.Activities.

In my opinion the return statement should read:

return _definition.Activities.Find(new Predicate<Activity>(delegate(Activity activity)
if (activity is PageState)
return string.Compare(((PageState)activity).Url, rawUrl, true, CultureInfo.CurrentCulture) == 0;
return false;
})) as PageState;

This is the exception we get:

System.InvalidCastException: Unable to cast object of type 'System.Workflow.Activities.EventDrivenActivity' to type 'Microsoft.Practices.PageFlow.WorkflowFoundation.Activities.PageState'.
at Microsoft.Practices.PageFlow.WorkflowFoundation.WorkflowFoundationPageFlowDefinition.<>c_DisplayClass1.<GetActivityByUrl>b_0(Activity activity) in C:\Projects\AGF\Agf\net2\Fwk\Pageflow\PageFlow.WorkflowFoundation\WorkflowFoundationPageFlowDefinition.cs:line 232
at System.Collections.Generic.List`1.Find(Predicate`1 match)

Othe rplaces exist in the code where this type of casting is used.