2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
6 class CustomException : Exception
10 class CustomException2 : Exception
14 class CrossDomain : MarshalByRefObject
16 public Action NewDelegateWithTarget ()
18 return new Action (Bar);
21 public Action NewDelegateWithoutTarget ()
23 return () => { throw new CustomException (); };
28 throw new CustomException ();
34 /* expected exit code: 3 */
35 static void Main (string[] args)
37 ManualResetEvent mre = new ManualResetEvent (false);
39 var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
41 var a = cd.NewDelegateWithTarget ();
42 var ares = a.BeginInvoke (delegate { throw new CustomException2 (); }, null);
47 } catch (CustomException) {
48 } catch (Exception ex) {
49 Console.WriteLine (ex);