So I dont know how to do that...
I have a program "Prg.cs" and a dll "Test.dll". I have try:
Assembly asm=Assembly.Load(@"C:\Users\Me\documents\visual studio 2013\Projects\Prg\Prg\bin\Debug\Test.dll");
Type runApp = asm.GetType();
dynamic thisApp = Activator.CreateInstance(runApp, this);
But gives me error:
An unhandled exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'C:\\Users\\Me\\documents\\visual studio 2013\\Projects\\Prg\\Prg\\bin\\Debug\\Test.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
Thanks!
You can do something like this:
class Program
{
static void Main(string[] args)
{
var dll = Assembly.LoadFile(@"C:\Test.dll");//The path of your dll
var theType = dll.GetType("dll.Test");
var c = Activator.CreateInstance(theType);
var method = theType.GetMethod("Output");//Your method in the class
method.Invoke(c, new object[]{@"Hello world"});
Console.ReadLine();
}
}
this link can help youstackoverflow.com/a/18362515/3383479
User contributions licensed under CC BY-SA 3.0