views:

265

answers:

3

Hi,

I got a NullReference problem using WWF and externaly raised events. The WWF state machine works together with a service instance raising events in the state machine to provide data and - of course - to change the state. While the "normal" operation works fine using events I got a strange problem.

To handle timeout scenarios I let the state initializer use a external timeout mechanism to register a callback in the menioned service. After the given time the callback function runs and shall raise the timeout event in the state machine. The events are defined like this:

event EventHandler<ExternalDataEventArgs> DeviceSysmapBrdcstTimeoutEvent;

and as mentioned work properly if not called from the timeout machanism. The ExternalDataEventArgs are created using valid Guids. The Excetion is raised accessing the delegate within the event:

System.Workflow.Activities.EventDeliveryFailedException was unhandled by user code
    Message="Event \"DeviceSysmapBrdcstTimeoutEvent\" on interface type \"...\" for instance id \"efa3da3d-8546-4fcf-bc56-bbec04df6d69\" cannot be delivered."
Source="System.Workflow.Activities"
    StackTrace:
        at System.Workflow.Activities.WorkflowMessageEventHandler.EventHandler(Object sender, ExternalDataEventArgs eventArgs)

Anyone an idea? Thanks.

+1  A: 

May you check if this link helpful?

http://www.mono-project.com/Gendarme.Rules.Concurrency#ProtectCallToEventDelegatesRule

Lex Li
+1  A: 

you may get the above exception for several reasons for details you need to check the Inner exceptions property

one possible reason might me that on time out you might want to transition from state A to State B but before state change you need to verify that you are actually in state A

POST THE INNER Exceptions detials for clarity

Snehal
+1  A: 

You should check the inner exception for more details. Check if you event service classes are marked [Serializable] and also set the WaitForIdle property to true in the event args.

CustomEventDataArgs eventArgs = new CustomEventDataArgs();
//
eventArgs.WaitForIdle = true;

Check if this fixes the problem.

Thanks.