微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – Type.GetType不工作

参见英文答案 > Type.GetType(“namespace.a.b.ClassName”) returns null16个
我刚刚注意到函数中的一个错误
Type.GetType("System.Uri");

返回值为null,而以下函数运行良好…

Type.GetType("System.string");
Type.GetType("System.bool");
Type.GetType("System.DateTime");

任何人都知道,为什么返回的Type为null?

编辑:删除Uri双重进入…

解决方法

Type.GetType(“System.Uri”)返回null的原因是该类型位于system.dll而不是mscorlib.dll.您必须使用上面提到的程序集限定名称.

来自MSDN:

typeName
Type: System.String

The assembly-qualified name of the type to get. See AssemblyQualifiedname. If the type is in the currently executing assembly or in Mscorlib.dll,it is sufficient to supply the type name qualified by its namespace.

原文地址:https://www.jb51.cc/csharp/98326.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐