Author Topic: C# Reflection - How to load C# assembly at run time?  (Read 1197 times)


  • Administrator
  • Full Member
  • *****
  • Posts: 69
C# Reflection - How to load C# assembly at run time?
« on: November 01, 2011, 12:17:27 pm »
The following code would load the C# assembly at run time with System.Reflection.Assembly.LoadFile(filename) . Then it try to get the class name called "CMyTestClass" and sets the value as "Software&Finance" for the property named "MyPropertyName".

Assembly assembly = Assembly.LoadFile("c:\\testserver.dll");
Type classType = assembly.GetType("CMyTestClass");
object classObjInstance = Activator.CreateInstance(classType);

Note in this case, you do not need to have the assembly file loaded in the GAC. And also it does not bound to a specific version of the assembly.

PropertyInfo info = classType.GetProperty("MyPropertyName");
object[] args = { "Software&Finance" };
info.SetValue(classObjInstance, args[0], null);


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1