First u dont need to add reference to the assembly nor you need to keep it in the bin directory as long as u use Assembly.LoadFrom().
- Assembly asm = Assembly.LoadFrom(@"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\firstmain\firstmain\bin\Debug\firstmain.dll");
Now assembly is loaded but u have to get a reference to the class cantaining the Main() method.
Do this as
- Type t = asm.GetType( [fully qualified name of the class cantaining the method Main] ,true, true);
Now we have reference to the class.Then you need to point to the specific method in the class.
Do this as
- MethodInfo m = t.GetMethod("Main", BindingFlags.Static | BindingFlags.Public);
Those binding flags specify what kind of method u wanna search.
If ur Main() is public and static use the above combination. (BindingFlags.Static | BindingFlags.Public)
Now you need to invoke the function.
Do this as
the first argument is for object(since it's static method u wanna access use null).Second argument specifies the arguments(again kept null).
Hope it helps !