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: 0 */
32 static void Main (string[] args)
34 ManualResetEvent mre = new ManualResetEvent (false);
36 var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
38 var action = cd.NewDelegateWithoutTarget ();
39 var ares = action.BeginInvoke (Callback, null);
46 static void Callback (IAsyncResult iares)
48 ((Action) ((AsyncResult) iares).AsyncDelegate).EndInvoke (iares);