Type.GetType 不起作用 [英] Type.GetType not working

查看:35
本文介绍了Type.GetType 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到函数中的一个错误:

I just noticed kind of a bug in the function:

Type.GetType("System.Uri");

返回值为空,而以下函数运行良好...

The return value is null whereas the following functions are working quite well...

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

...

有谁知道,为什么返回的Type为null?

Anyone knows, why the returned Type is null?

删除了 Uri 双重条目...

推荐答案

Type.GetType("System.Uri") 返回 null 的原因是类型位于 system.dll 而不是 mscorlib.dll.您必须使用如上所述的程序集限定名称.

The reason that Type.GetType("System.Uri") returns null is that the type is located in system.dll instead of mscorlib.dll. You must use the assembly-qualified name as noted above.

来自 MSDN:

类型名称类型:System.String

typeName Type: System.String

要获取的类型的程序集限定名称.请参阅AssemblyQualifiedName.如果类型在当前执行的程序集中或 Mscorlib.dll 中,则提供由其命名空间限定的类型名称就足够了.

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.

这篇关于Type.GetType 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆