2 using System.Reflection;
4 using System.Security.Permissions;
8 private const string filename = "library1a";
10 static int GetTypeFalse (Assembly a)
12 string typename = "InheritanceDemand";
13 Type t = a.GetType (typename, false);
15 Console.WriteLine ("*0* Get null for type '{0}' with security.", typename);
18 Console.WriteLine ("*1* Can get type '{0}' with security (false).", typename);
23 static int GetTypeTrue (Assembly a)
26 string typename = "InheritanceDemand";
27 Type t = a.GetType (typename, true);
28 Console.WriteLine ("*1* Can get type '{0}' with security (true).", t);
31 catch (SecurityException se) {
32 Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
37 static int GetTypes (Assembly a)
40 Type[] ts = a.GetTypes ();
41 Console.WriteLine ("*1* Can get all types from assembly '{0}' loaded. {1} types present.", filename, ts.Length);
44 catch (ReflectionTypeLoadException rtle) {
45 Console.WriteLine ("*0* Expected ReflectionTypeLoadException\n{0}", rtle);
46 Console.WriteLine ("Types ({0}):", rtle.Types.Length);
47 for (int i=0; i < rtle.Types.Length; i++) {
48 Console.WriteLine ("\t{0}", rtle.Types [i]);
50 Console.WriteLine ("LoaderExceptions ({0}):", rtle.LoaderExceptions.Length);
51 for (int i=0; i < rtle.LoaderExceptions.Length; i++) {
52 Console.WriteLine ("\t{0}", rtle.LoaderExceptions [i]);
61 Assembly a = Assembly.Load (filename);
63 Console.WriteLine ("*2* Couldn't load assembly '{0}'.", filename);
67 string typename = "NoSecurity";
68 Type t = a.GetType (typename);
70 Console.WriteLine ("*3* Cannot get type '{0}' without security.", typename);
74 int err = GetTypeFalse (a);
78 err = GetTypeTrue (a);
85 catch (ReflectionTypeLoadException rtle) {
86 Console.WriteLine ("*4* Expected ReflectionTypeLoadException");
89 catch (SecurityException se) {
90 Console.WriteLine ("*5* Unexpected SecurityException\n{0}", se);
94 Console.WriteLine ("*6* Unexpected Exception\n{0}", e);