2 using System
.Diagnostics
;
3 using System
.Threading
;
4 using System
.Threading
.Tasks
;
5 using System
.Runtime
.Remoting
.Messaging
;
7 class CustomException
: Exception
11 class CrossDomain
: MarshalByRefObject
13 public Action
NewDelegateWithTarget ()
15 return new Action (Bar
);
18 public Action
NewDelegateWithoutTarget ()
20 return () => { throw new CustomException (); }
;
25 throw new CustomException ();
31 /* expected exit code: 255 */
32 static void Main (string[] args
)
34 if (Environment
.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
35 AppDomain
.CurrentDomain
.UnhandledException
+= (s
, e
) => {};
37 ManualResetEvent mre
= new ManualResetEvent (false);
39 var ad
= AppDomain
.CreateDomain ("ad");
41 if (Environment
.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
42 ad
.UnhandledException
+= (s
, e
) => {};
44 var cd
= (CrossDomain
) ad
.CreateInstanceAndUnwrap (typeof(CrossDomain
).Assembly
.FullName
, "CrossDomain");
46 var action
= cd
.NewDelegateWithoutTarget ();
47 var ares
= action
.BeginInvoke (Callback
, null);
54 static void Callback (IAsyncResult iares
)
56 ((Action
) ((AsyncResult
) iares
).AsyncDelegate
).EndInvoke (iares
);