Tuesday, June 19, 2007

EventDeliveryFailedException in State Machine Workflow

I am currently diving into Windows Workflow Foundation. During my first steps (kind of hello world examples), some errors occurs ... Sometimes it's hard to resolve some errors...
Let's have a look at the EventDeliveryFailedException ...

Has this error ever occured?
An unhandled exception of type 'System.Workflow.Activities.EventDeliveryFailedException' occurred in System.Workflow.Activities.dll.
Additional information: Event "AskWorkflowValues" on interface type "App.GeneralLib.IMyService" for instance id "8385d402-19fb-4549-a765-c7e2b4c0a856" cannot be delivered.

When adding an eventDrivenActivity to a State Machine's worfklow State Activity, you wouldn't receive this exception when firing an event from the host application to the workflow.

This exception only occurs, in my case, when adding an eventDrivenActivity to the State Machine's workflow self... (and not to a state activity).


The host application fires an event through a local service method. In that method you must specify the ExternalDataEventArgs parameter. Now to resolve the problem you must set the WaitForIdle property of the ExternalDataEventArgs instance.

If this property is true then the workflow should go idle before raising the event by the host application through the local service. At default, this property is false and the event can only be catched by an EventDrivenActivity within a State Activity. So, in other words the workflow has to process it things first before this event can be deliverd. That's why the WaitForIdle must be true.

Local Service Interface

public interface IMyService
event EventHandler AskWorkflowValues;

Local Service implementation

public class MyService:IMyService
public void OnAskWorkflowValues(ExternalDataEventArgs e)
if (AskWorkflowValues != null)
AskWorkflowValues(null, e);

Host application

//calling local service's method to fire an event to the state machine workflow


ExternalDataEventArgs GetEventArgs(Guid instanceId)
ExternalDataEventArgs e = new ExternalDataEventArgs(instanceId);
e.WaitForIdle = true;
return e;

Wednesday, June 13, 2007

Debugging Workflows in Visual Studio 2005

To debug your workflow library, execute following steps:

  1. Compile both projects (GUI/Business Workflow library)

  2. Go the the Workflow Library project's properties

  3. Go to the Debug tab

  4. Set the 'Start External Program' below the 'Start Action' section

  5. Browse to the compiled GUI project and select the executable (.exe).

  6. Make sure that your Business Workflow Library is set as startup project