summaryrefslogtreecommitdiff
path: root/mono/tests/assemblyresolve_event4.cs
blob: fa12f01984204dc86dd0fa9aed0f5e9b2242365d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.IO;
using System.Reflection;

class App
{
	public static int Main ()
	{
		AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler (MyResolveEventHandler);

		try {
			var a = Assembly.Load ("test");
			foreach (Type t in a.GetTypes ()) {
				Console.WriteLine ("pp: " + t + " " + t.BaseType);
			}
		} catch (Exception ex) {
			Console.WriteLine ("Caught exception: {0}", ex);
			return 1;
		}

		return 0;
	}

	static Assembly MyResolveEventHandler (object sender, ResolveEventArgs args)
	{
		var path = Path.Combine (Directory.GetCurrentDirectory (), "assemblyresolve", "deps");
		if (args.Name == "test" && args.RequestingAssembly == null)
			return Assembly.LoadFile (Path.Combine (path, "test.dll"));
		if (args.Name == "TestBase, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" && args.RequestingAssembly.GetName ().Name == "test")
			return Assembly.LoadFile (Path.Combine (path, "TestBase.dll"));

		throw new InvalidOperationException (String.Format ("Unexpected parameter combination {0} {1}", args.Name, args.RequestingAssembly));
	}
}