[System.Runtime.Serialization] Static writer fix.
[mono.git] / mono / tests / unhandled-exception-7.cs
1 using System;
2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
5 using System.Runtime.Remoting.Messaging;
6
7 class CustomException : Exception
8 {
9 }
10
11 class CrossDomain : MarshalByRefObject
12 {
13         public Action NewDelegateWithTarget ()
14         {
15                 return new Action (Bar);
16         }
17
18         public Action NewDelegateWithoutTarget ()
19         {
20                 return () => { throw new CustomException (); };
21         }
22
23         public void Bar ()
24         {
25                 throw new CustomException ();
26         }
27 }
28
29 class Driver
30 {
31         /* expected exit code: 0 */
32         static void Main (string[] args)
33         {
34                 ManualResetEvent mre = new ManualResetEvent (false);
35
36                 var cd = (CrossDomain) AppDomain.CreateDomain ("ad").CreateInstanceAndUnwrap (typeof(CrossDomain).Assembly.FullName, "CrossDomain");
37
38                 var action = cd.NewDelegateWithoutTarget ();
39                 var ares = action.BeginInvoke (Callback, null);
40
41                 Thread.Sleep (5000);
42
43                 Environment.Exit (1);
44         }
45
46         static void Callback (IAsyncResult iares)
47         {
48                 ((Action) ((AsyncResult) iares).AsyncDelegate).EndInvoke (iares);
49         }
50 }