Is Button also alias name

  • Thread starter Thread starter Kimmo Laine
  • Start date Start date
K

Kimmo Laine

Hi,

the following code works fine:

Type t = Type.GetType( "System.Int32" );

Whats wrong with this one:

Type t = Type.GetType( "System.Windows.Forms.Button" );


- Kimmo Laine
 
Kimmo,
the following code works fine:

Type t = Type.GetType( "System.Int32" );

Whats wrong with this one:

Type t = Type.GetType( "System.Windows.Forms.Button" );

When you specify only a type name, Type.GetType only searches the
calling assembly and Mscorlib. Since Int32 is implemented in Mscorlib
it finds that, but not Button which is in the System.Windows.Forms
assembly.

The solution is to either specify the full type and assembly name

Type.GetType( "System.Windows.Forms.Button, System.Windows.Forms, " +
"Version=1.0.5000.0, Culture=neutral, " +
"PublicKeyToken=b77a5c561934e089, Custom=null" );

or get an System.Reflection.Assembly reference for the
System.Windows.Forms assembly and call GetType on that, or (if you
have System.Windows.Forms.dll referenced) use C#'s typeof() operator.

typeof(System.Windows.Forms.Button)



Mattias
 
Back
Top