在web项目中 运行时貌似需要指定从dll中获取实体

  1. Type typeofControl = null;
  2. Assembly tempAssembly;
  3. //web目录
  4. tempAssembly = Assembly.LoadFrom(HttpContext.Current.Server.MapPath("~/") + "bin/DrwmePMS.Model.dll");
  5. //普通
  6. //tempAssembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory+ "/bin/DrwmePMS.Model.dll");
  7. typeofControl = tempAssembly.GetType("DrwmePMS.Model.Cycle");
  8. var obj = Activator.CreateInstance(typeofControl, null);

普通创建

Activator.CreateInstance(Type.GetType("DrwmePMS.Model.Cycle"), null);