c# - Exception escapes from workflow despite TryCatch activity -


i have workflow inside windows service loop performs work periodically. work done inside trycatch activity. try property transactionscope activity wraps custom activities read , update database. when transaction fails, expect exception caused caught trycatch. however, workflow aborts. workflow have following:

var wf = new while(true) {     body = new sequence     {         activities =         {             new trycatch             {                 try = new transactionscope                 {                     isolationlevel = isolationlevel.readcommitted,                     body = new sequence                     {                         activities = { ..custom database activities.. }                     },                     abortinstanceontransactionfailure = false                 },                 catches =                 {                     new catch<exception>                     {                         action = new activityaction<exception>                         {                             argument = exception,                             handler = ..log error..                         }                     }                 }             },             new delay { duration = new inargument<timespan>(duration) }         }     }, } 

in case, it's possible database unavailable transaction won't commit. happens in case workflow aborts following exception:

system.operationcanceledexception: error processing current work item has caused workflow abort.

the inner exception is:

system.transactions.transactionexception: operation not valid state of transaction.

this makes sense because have switched off database. however, why isn't exception handled trycatch activity?

edit 1: additional information. run workflow using workflowapplication class. better see what's going on, specified properties aborted , onunhandledexception. when exception occurs, goes directly aborted , onunhandledexception skipped (although unhandled exception).

edit 2: enabled debug log , provides additional insight. 'custom database activities' run completion. first event log entry indicates wrong verbose level message: the runtime transaction has completed state 'aborted'. next see information message: workflowinstance id: 'dbd1ba5c-2d8a-428c-970d-21215d7e06d9' e2e activity (not sure means). , information message after is: activity 'system.activities.statements.transactionscope', displayname: 'transaction run checks', instanceid: '389' has completed in 'faulted' state.

after message, see each parent (including trycatch activity) completes in 'faulted' state, ending abortion of workflow.

edit 3: clear, works expected when exception occurs in of 'custom database activities'. exception caught , workflow continues. goes wrong when transaction can't commit @ end of transactionscope. see following stacktrace logged aborted callback:

at system.transactions.transactionstateindoubt.rollback(internaltransaction tx, exception e) @ system.transactions.transaction.rollback(exception e) @ system.activities.runtime.activityexecutor.completetransactionworkitem.handleexception(exception exception) 

if follow calls transactionscope.oncompletion(...), arrive @ activityexecutor class stacktrace.

transactions commit asynchronously , after fact. can't react failure of transaction commit because of problem @ resource manager level.

as pointed out, can deal exceptions occur in activities. if @ tracking records workflow guess see trycatch activity closed prior transaction abort.

many years ago when program manager in com+ team studied issue because people want transactional component (or workflow) in case able react transaction abort.

the async nature of resolution of transaction means cannot react in component itself. solution react in caller can take action.

the design assumption once transaction has aborted, nothing state aqcuired in transaction can safely used - discarded because transaction aborted.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -