Can I load a .NET assembly at runtime and instantiate a type knowing only the name?

后端 未结 13 2321
-上瘾入骨i
-上瘾入骨i 2020-11-22 17:21

Is it possible to instantiate an object at runtime if I only have the DLL name and the class name, without adding a reference to the assembly in the project? The class imple

13条回答
  •  情歌与酒
    2020-11-22 17:48

    You can do this things on this way:

    using System.Reflection;
    
    Assembly MyDALL = Assembly.Load("DALL"); //DALL name of your assembly
    Type MyLoadClass = MyDALL.GetType("DALL.LoadClass"); // name of your class
     object  obj = Activator.CreateInstance(MyLoadClass);
    

提交回复
热议问题