2 using System.Diagnostics;
3 using System.Reflection;
6 public static void staticCrash () {
11 public void callStaticCrash () {
18 public void Throw () {
19 throw new Exception ();
22 public void Throw<T3> () {
23 throw new Exception ();
27 class Bar<T> : Foo<object, T> {
31 public static void callCallStaticCrash<T> () {
32 Gen<T> gt = new Gen<T> ();
33 gt.callStaticCrash ();
36 public static bool test (Exception exc, Type type) {
37 StackTrace st = new StackTrace (exc);
38 for (int i = 0; i < st.FrameCount; ++i) {
39 StackFrame sf = st.GetFrame (i);
40 MethodBase m = sf.GetMethod ();
43 Type t = m.DeclaringType;
44 if (m.IsGenericMethod) {
45 Type[] margs = m.GetGenericArguments ();
46 //Console.WriteLine (m.Name);
47 if (margs.Length != 1)
49 if (margs [0] != type)
52 if (t.IsGenericType) {
53 Type[] targs = t.GetGenericArguments ();
54 //Console.WriteLine (t.FullName);
55 if (targs.Length != 1)
57 if (targs [0] != type)
64 public static int Main () {
66 callCallStaticCrash <int> ();
67 } catch (Exception exc) {
68 if (!test (exc, typeof (int)))
72 callCallStaticCrash <object> ();
73 } catch (Exception exc) {
74 if (!test (exc, typeof (object)))
78 callCallStaticCrash <string> ();
79 } catch (Exception exc) {
80 if (!test (exc, typeof (string)))
84 callCallStaticCrash <Gen<string>> ();
85 } catch (Exception exc) {
86 if (!test (exc, typeof (Gen<string>)))
90 // Exception thrown in inherited method with different generic context
93 new Bar <string> ().Throw ();
94 } catch (Exception ex) {
95 Console.WriteLine (new StackTrace (ex));
99 new Bar <string> ().Throw<Bar<string>> ();
100 } catch (Exception ex) {
101 Console.WriteLine (new StackTrace (ex));