Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leachdaniel/e7a397633a31695701305f7701cbdeee to your computer and use it in GitHub Desktop.
Save leachdaniel/e7a397633a31695701305f7701cbdeee to your computer and use it in GitHub Desktop.
Dynamically Load an Assembly and call a method on it
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace InterfaceCaller
{
class Program
{
static void Main(string[] args)
{
// get the assembly from the path in argument
var asm = Assembly.LoadFile(args[0]);
// get the type name
var type = asm.GetType(args[1]);
var runnable = Activator.CreateInstance(type);
if (runnable == null) throw new Exception("the type was not runnable");
// call with args[2]'
var method = type.GetMethod(args[2]);
// method has no arguments
method.Invoke(runnable, new object[] { });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment