GetType(string) issue

  • Thread starter Thread starter VR
  • Start date Start date
V

VR

Hello,

Type oType1 = Type.GetType("System.Int32");
Type oType2 = Type.GetType("System.Windows.Forms.Label");

After executing the code above, oType1 is set to
System.Int32 (valid type), while oType2 is set to null.

I do have at the top of the file:
using System.Windows.Forms;

and

System.Windows.Forms are also seen in References.

What am I doing wrong? Thanks for the help.

VR
 
What am I doing wrong?

The function only searches Mscorlib.dll and the calling assembly by
default. To get it to look in another assembly, you have to specify
the assembly name as well

Type oType2 = Type.GetType("System.Windows.Forms.Label,
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089");

But since you obviously have a compile time reference to the assembly,
it would be easier to just do

Type oType2 = typeof(System.Windows.Forms.Label);



Mattias
 
Thanks, Mattias.

It sure does work.
-----Original Message-----


The function only searches Mscorlib.dll and the calling assembly by
default. To get it to look in another assembly, you have to specify
the assembly name as well

Type oType2 = Type.GetType("System.Windows.Forms.Label,
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089");

But since you obviously have a compile time reference to the assembly,
it would be easier to just do

Type oType2 = typeof(System.Windows.Forms.Label);



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.
 
Back
Top