【发布时间】:2012-10-14 10:21:20
【问题描述】:
我的应用程序中有一段代码(引用 System.Windows.Forms),它尝试解析 Form 类的类型信息,如下所示:
Type tForm = Type.GetType("System.Windows.Forms.Form");
dynamic instance = Activator.CreateInstance(tForm);
但Activator.CreateInstance 失败,因为tForm 为空。
我该如何解决这个问题?
编辑:类型必须在运行时可解析!
【问题讨论】:
-
当前程序集的项目是否有对 System.Windows.Forms 的引用? (如果您使用的是多项目解决方案)
-
为什么不只是
typeof(System.Windows.Forms.Form)? -
AppDomain.CurrentDomain.GetAssemblies() 是否显示 System.Windows.Forms 已加载?
-
@Jodrell 因为类型信息正在运行时解析
-
@activwerx,或者,在这种情况下,类型信息在运行时没有被解析。我实际上的意思是为什么要动态地这样做?
标签: c# .net reflection types