call method at runtime

fishhead picture fishhead · Jan 31, 2010 · Viewed 7.3k times · Source

I am wondering if it is possible to load a .net DLL at runtime, view the methods available and execute one at runtime.

If this is possible could you point me in the right direction

Answer

codekaizen picture codekaizen · Jan 31, 2010

Generally, you use System.Reflection classes to do this task.

Specifically, you'd load the DLL via Assembly.Load (or Assembly.LoadFrom) and then call Assembly.GetTypes and then for each type call Type.GetMethods. When you have a MethodInfo, you can call MethodInfo.Invoke on it.