3 using System
.Reflection
;
4 using System
.Threading
;
16 public class StaticInitFails
{
18 public static string s
;
20 static StaticInitFails () {
22 throw new Exception ();
26 public static void foo () {
27 Console
.WriteLine (s
);
37 * This is really at test of the compiler: it should init
38 * last before getting here.
45 public static int Main() {
51 // Regression test for bug #59193 (shared runtime wrappers)
52 ConstructorInfo con1
= typeof (A
).GetConstructor (BindingFlags
.Instance
| BindingFlags
.Public
| BindingFlags
.NonPublic
, null, new Type
[1] { typeof (int) }
, null);
53 ConstructorInfo con2
= typeof (B
).GetConstructor (BindingFlags
.Instance
| BindingFlags
.Public
| BindingFlags
.NonPublic
, null, new Type
[1] { typeof (int) }
, null);
55 con1
.Invoke (new Object
[] { 0 }
);
56 con2
.Invoke (new Object
[] { 0 }
);
58 // Test what happens when static initialization throws an exception
59 // First start a thread which will trigger the initialization
60 Thread t
= new Thread (new ThreadStart (Run
));
65 // While the thread waits, trigger initialization on this thread too so this
66 // thread will wait for the other thread to finish initialization
71 catch (TypeInitializationException ex
) {
74 // Try again synchronously
79 catch (TypeInitializationException ex
) {
85 private static void Run () {
87 StaticInitFails
.foo ();
93 private static void Run2 () {
94 StaticInitFails
.foo ();