using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
+using System.Runtime.Remoting.Messaging;
class CustomException : Exception
{
}
-class CustomException2 : Exception
-{
-}
-
class CrossDomain : MarshalByRefObject
{
public Action NewDelegateWithTarget ()
class Driver
{
- /* expected exit code: 0 */
+ /* expected exit code: 255 */
static void Main (string[] args)
{
+ if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
+ AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
+
ManualResetEvent mre = new ManualResetEvent (false);
- var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
+ var ad = AppDomain.CreateDomain ("ad");
+
+ if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
+ ad.UnhandledException += (s, e) => {};
- var a = cd.NewDelegateWithoutTarget ();
- var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
+ var cd = (CrossDomain) ad.CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
- try {
- a.EndInvoke (ares);
- Environment.Exit (4);
- } catch (CustomException) {
- } catch (Exception ex) {
- Console.WriteLine (ex);
- Environment.Exit (3);
- }
+ var action = cd.NewDelegateWithoutTarget ();
+ var ares = action.BeginInvoke (Callback, null);
- Environment.Exit (0);
+ Thread.Sleep (5000);
+
+ Environment.Exit (1);
+ }
+
+ static void Callback (IAsyncResult iares)
+ {
+ ((Action) ((AsyncResult) iares).AsyncDelegate).EndInvoke (iares);
}
}