在尝试通过反射实例化WebProxy实例时,我遇到了这个奇怪的问题:
Dim proxyType As Type = GetType(System.Net.WebProxy)
MsgBox(proxyType.FullName)
Dim reflProxyType As Type = Type.GetType(proxyType.FullName)
MsgBox(reflProxyType.FullName) ' Here, reflProxyType is null => NullReferenceException将第一行更改为其他系统名称空间(即System.Text.StringBuilder或System.String)运行良好。
Dim systemType As Type = GetType(System.Text.StringBuilder)
MsgBox(systemType.FullName)
Dim reflSystemType As Type = Type.GetType(systemType.FullName)
MsgBox(reflSystemType.FullName) ' Here, everything works fine这种行为有什么原因吗?我是不是漏掉了什么?微软是否对System.dll设置了一些限制?
发布于 2012-09-27 22:14:50
答案就在Type.GetType (string)的MSDN docs中
参数
typeName类型: System.String
要获取的类型的程序集限定名称。参见AssemblyQualifiedName。如果类型在当前执行的程序集中或在Mscorlib.dll,中,则只需提供由其命名空间限定的类型名称即可。
WebProxy类在System.dll中,而不是Mscorlib.dll中。因此,您必须执行以下任一操作:
Assembly.GetType(string)方法。https://stackoverflow.com/questions/12623380
复制相似问题