I have a need in my app to know when an underlying component that is executed dynamically threw a process corrupted state exception so I can log it, and mark the component as bad for loading again and crash my process.
The execution of this component is performed asynchronously and I am using Async.Catch to handle that exception. I tried the following code to test the behavior of Async.Catch and it seems to me that Async.Catch is hung. This is an undesirable effect for me and am suspecting that all PCSE will result in the same behavior.
Anyone know how to get out of this situation?
let a = async {
System.Threading.Thread.CurrentThread.Abort()
}
let b = async {
let! m = Async.Catch a
return match m with
| Choice1Of2 p -> "hello"
| Choice2Of2 e -> "Caught: " + e.ToString()
}
Async.RunSynchronously b;;
EDIT 1: I found the documentation that pointing me to use either HandleProcessCorruptedStateExceptionsAttribute
together with SecurityCriticalAttribute
or use a config entry legacyCorruptedStateExceptionsPolicy=true
. I don't want to use a config entry if at all possible.
EDIT 2: Based on the suggestion in the comment, I modified the let binding for 'b' as follows:
let b = async {
try
let! m = Async.Catch a
return "hello"
with
| :? System.Threading.ThreadAbortException as e -> return "Caught: " + e.ToString()
}
The program still hangs without returning or throwing.