I create a Class Library project and I build it.now i copy the Dll to “C:\”.Now i want to open this Dll with reflection:
using System.Reflection;
byte[] assem = System.IO.File.ReadAllBytes(@"c:\Company.dll");
var loadedAssem = Assembly.Load(assem);
Type thePersonType = loadedAssem.GetType();
var theObj = loadedAssem.CreateInstance("Company.Person");
// or var theObj = loadedAssem.CreateInstance("Company.Person")as IPlugin ;
Type[] paramTypes = new Type[1];
paramTypes[0] = Type.GetType("System.String");
MethodInfo PersonInfo = thePersonType.GetMethod("FullName", paramTypes);
Object[] parameters = new Object[1];
parameters[0] = "Mr. ";
Object returnVal = PersonInfo.Invoke(theObj, parameters);
MessageBox.Show(returnVal.ToString());
I cant Invoke my “FullName” method.
this is my Interface:
public interface IPlugin
{
String FullName(String PreName);
}
and this is my Person Class in my DLL:
public class Person:IPlugin
{
public int PersonID { get; set; }
public String PersonName { get; set; }
public String PersonLName { get; set; }
public String FullName(String PreName)
{
return PreName+this.PersonName + this.PersonLName;
}
}
I solve the problem with this code.and we shold to use interface “IPlugin” in a seperate class library and use in other project.