0

this is a strange question. i can load 15 Dll's from plugins directory. But i have basePluginToRunothers.DLL which task execute other 14 dlls. My Starter dll is basePluginToRunothers.DLL. How to run other dlls by using basePluginToRunothers.DLL in AppDomain.CurrentDomain?

enter image description here

How to use abc.dll,xyz.dll, klm.dll by using basePluginToRunothers.DLL which has RUN method? NOTE: ican load all dlls. other dlls will be execute over basePluginToRunothers'run method.

Community
  • 1
  • 1
loki
  • 2,926
  • 8
  • 62
  • 115
  • I think, you are able to load basePluginToRunothers.dll using reflection from main program. – Romil Kumar Jain May 08 '12 at 13:08
  • yes i can . other dlls will be execute over basePluginToRunothers'run method. – loki May 08 '12 at 13:16
  • Please let me know that are you able to execute all other 14 dll's or not. What exact issue you are facing? – Romil Kumar Jain May 08 '12 at 13:19
  • i can execute other dllbut i want to execute 14dlls in basePluginToRunothers. basePluginToRunothers.Execute(select.FROM(AppdomainOTherDLLS)) – loki May 08 '12 at 13:23
  • As per me, you have Execute/Run method in basePluginToRunothers dll. In this function, you are doing the reflection to load the all 14 dll's and executing the RUN method of all 14 dll's. Please correct me if your approach is different. – Romil Kumar Jain May 08 '12 at 13:26
  • First: Load All DLLS in Appdomain.CurrentDomain SECOND: basePluginToRunothers Execute method.Start other dlls execute method – loki May 08 '12 at 13:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11020/discussion-between-programmerist-and-romil) – loki May 08 '12 at 13:31

1 Answers1

2
public static void ReflectionInvoke()
        {
            int sum = 0;
            int sub = 0;
            int sum1 = 0;
            int sum2 = 0;
            MethodInfo mi = default(MethodInfo);

            // Loading the assembly 
            Assembly reflectionAssemby = Assembly.LoadFile(@"C:\RelectionDLL.dll");
            // Get type of class from loaded assembly
            Type reflectionClassType = reflectionAssemby.GetType("ReflectionDLL.ReflectionClass");
            // Create instance of the class
            object objReflection = Activator.CreateInstance(reflectionClassType);

            // Playing with property read/write
            PropertyInfo intPropInfo = reflectionClassType.GetProperty("intProperty");
            int i = Convert.ToInt32(intPropInfo.GetValue(objReflection, null));
            // Reading value
            intPropInfo.SetValue(objReflection, 55, null);
            // writing value
            int k = Convert.ToInt32(intPropInfo.GetValue(objReflection, null));
            // Reading value
            // Playing with property read
            PropertyInfo strPropInfo = reflectionClassType.GetProperty("strProperty");
            String str = (String)strPropInfo.GetValue(objReflection, null);
            // Reading value
            // Playing with property write
            PropertyInfo dtPropertyInfo = reflectionClassType.GetProperty("dtProperty");
            dtPropertyInfo.SetValue(objReflection, DateTime.Now, null);
            // writing value
            // Playing with static property read/write
            PropertyInfo staticPropertyInfo = reflectionClassType.GetProperty("staticProperty");
            int i1 = Convert.ToInt32(staticPropertyInfo.GetValue(null, null));
            // Reading value
            staticPropertyInfo.SetValue(null, 111, null);
            // writing value
            int k1 = Convert.ToInt32(staticPropertyInfo.GetValue(null, null));
            // Reading value
            // Invoking instance method
            //


            Console.WriteLine("IInd Way to call methods");
            reflectionClassType.InvokeMember("pub_Inst_NoReturn_Function", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, objReflection, null);
            reflectionClassType.InvokeMember("pri_Inst_NoReturn_Function", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, objReflection, null);
            sum = Convert.ToInt32(reflectionClassType.InvokeMember("pub_inst_Add_TwoNos", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, objReflection, new object[] { 55, 56 }));
            sub = Convert.ToInt32(reflectionClassType.InvokeMember("pri_inst_Subtract_TwoNos", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, objReflection, new object[] { 55, 56 }));

            // Invoking static method
            reflectionClassType.InvokeMember("pub_static_NoReturn_Function", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, null);
            reflectionClassType.InvokeMember("pri_static_NoReturn_Function", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, null);
            sum1 = Convert.ToInt32(reflectionClassType.InvokeMember("pub_static_Add_TwoNos", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, new object[] { 55, 56 }));
            sum2 = Convert.ToInt32(reflectionClassType.InvokeMember("pri_static_Subtract_TwoNos", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { 55, 56 }));

            Console.WriteLine();
        }
Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92