[tests] Test loading references from LoadFrom and LoadFile contexts
[mono-project.git] / mono / tests / assemblyresolve_event4.cs
blobb5b73f50cb08a6d067d039c2c8b2b42c48c88f2f
1 using System;
2 using System.IO;
3 using System.Reflection;
5 class App
7 public static int Main ()
9 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler (MyResolveEventHandler);
11 try {
12 var a = Assembly.Load ("Test");
13 foreach (Type t in a.GetTypes ()) {
14 Console.WriteLine ("pp: " + t + " " + t.BaseType);
16 } catch (Exception ex) {
17 Console.WriteLine ("Caught exception: {0}", ex);
18 return 1;
21 return 0;
24 static Assembly MyResolveEventHandler (object sender, ResolveEventArgs args)
26 if (args.Name == "Test" && args.RequestingAssembly == null)
27 return Assembly.LoadFile (Path.Combine (Directory.GetCurrentDirectory (), "assemblyresolve_deps", "Test.dll"));
28 if (args.Name == "TestBase, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" && args.RequestingAssembly.GetName ().Name == "Test")
29 return Assembly.LoadFile (Path.Combine (Directory.GetCurrentDirectory (), "assemblyresolve_deps", "TestBase.dll"));
31 throw new InvalidOperationException (String.Format ("Unexpected parameter combination Name=\"{0}\" RequestingAssembly=\"{1}\"", args.Name, args.RequestingAssembly));