-1

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!

  • 1
    Possible duplicate of [this question](http://stackoverflow.com/questions/18362368/loading-dlls-at-runtime-in-c-sharp) – Icemanind Apr 18 '14 at 14:29

1 Answers1

0

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

Community
  • 1
  • 1
  • I have updated the answer. in this line `var theType = dll.GetType("dll.Test");` you must use the Class in your case it is `Test` inside your dll –  Apr 19 '14 at 09:32