I just came across this oddity when trying to instantiate a WebProxy instance through reflection :
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
Changing the first line to other System namespaces (ie. System.Text.StringBuilder or System.String) works fine.
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
Is there any reason for this behavior ? Am I missing something ? Did MS set up some restrictions on System.dll ?
The answer is in the MSDN docs for
Type.GetType (string)The
WebProxyclass is in System.dll, not Mscorlib.dll. Therefore, you must either:Assembly.GetType(string)method.