You must Sign In to post a response.
  • Category: ASP.NET

    Regarding Activator.CreateInstance in C#

    Hi all,

    I am using Activator.CreateInstance in my code as follows:

    Interface I1 = null;
    I1= System.Reflection.Assembly.LoadFrom(assemblyLocation) // this returns assembly location
    Type vaType = I1.GetType(type , true); // here type comes from database
    I1 = Activator.CreateInstance(vaType) as Interface;

    But, this line returns null.

    Can anyone help that why it returns null

    Thanks in advance
  • #762912
    Hi,

    Can you try like this for using Activator.CreateInstance

    using System.Reflection;

    Assembly asm = Assembly.GetEntryAssembly();
    string path = asm.GetName().ToString();
    path = path.Substring(0, path.IndexOf(","));
    string formname = path + "." + "YourClassName";
    Type formtype = asm.GetType(formname);
    var f = Activator.CreateInstance(formtype);

    Thanks & Regards,
    Mahesh Durgam


Sign In to post your comments