// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Reflection; namespace A { public class C { private object o; private MethodInfo mi1; private MethodInfo mi2; public C() { o = Assembly.LoadFrom("A.orig.dll").CreateInstance("A.C"); // note that .Load does not work here due to manifest mismatch Type t = o.GetType(); mi1 = t.GetMethod("M1", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null); mi2 = t.GetMethod("M1", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null); } public void M1() { Console.WriteLine("Before M1 (R)"); mi1.Invoke(o, new object[0]); Console.WriteLine("After M1 (R)"); } public void M2() { Console.WriteLine("Before M2 (R)"); mi2.Invoke(o, new object[0]); Console.WriteLine("After M2 (R)"); } } }