mardi 18 août 2015

dynamically create class object by using assemblyname and type of class

I have a console application in which I declared a class which is define under a namespace . I want to create an instance of that class at runtime using assemblyname and class name.I tried the below code

 var objAssembly = Assembly.Load(assemblyName);
            var  objType = objAssembly.GetType(className);
            var obj = Activator.CreateInstance(objType);

But it is not working.Below is the class structure

    namespace ReportService.ReportWriters
{
    class ExcelWriter : IReportWriter
    {
    }

}





Aucun commentaire:

Enregistrer un commentaire