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

后端 未结 13 2304
-上瘾入骨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:55

    ((ISomeInterface)Activator.CreateInstance(Assembly.LoadFile("somePath").GetTypes()[0])).SomeInterfaceMethod();
    

提交回复
热议问题