C#.NET - Type.GetType(" System.Windows.Forms.Form中")返回nullGetType、QUOT、NET、Type

2023-09-03 07:54:49 作者:靜候婲開雁归来

我在我的应用程序的code的片段(它引用System.Windows.Forms的的),它试图解决的类型信息的表格像这样的类:

I have a snippet of code in my application (which references System.Windows.Forms) which attempts to resolve type information for a Form class like so:

Type tForm = Type.GetType("System.Windows.Forms.Form");
dynamic instance = Activator.CreateInstance(tForm);

Activator.CreateInstance 失败,因为 TForm的为空。

but Activator.CreateInstance fails because tForm is null.

我要如何解决这个问题?

How do I solve this?

编辑:类型必须是可解析在运行时

推荐答案

您需要使用的类型的程序集限定名称

You need to use assembly-qualified name of the type

Type tForm = Type.GetType("System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");