Type.GetType

  • Thread starter Thread starter AlexS
  • Start date Start date
A

AlexS

I have app, which has usings for System.Windows.Forms

But when I do Type.GetType("TreeView") or use full class name for TreeView
I get null.

Why?

Anything I miss? What are the rules of use for Type.GetType?
Thx
 
AlexS said:
I have app, which has usings for System.Windows.Forms

But when I do Type.GetType("TreeView") or use full class name for TreeView
I get null.

Why?

Anything I miss? What are the rules of use for Type.GetType?

As documented, if you use just the type name, it will only search in
mscorlib and the executing assembly. You should either explicitly load
the assembly first, and then use Assembly.GetType, or specify the full
name of the assembly in the call to Type.GetType (including version
information etc if the assembly is in the GAC).
 
Thanks for a hint

I was able to get type using string
"System.Windows.Forms.TreeView,System.Windows.Forms, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"

If any part of full assembly name is omitted Type.GetType fails. If type
name is not fully qualified search fails too.

Unfortunately docs in Framework SDK (help) and on MSDN site are different.
Would be much nicer if MS would update SDK help and samples too.

Thx

Alex
 
Back
Top