Type.GetType

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AlexS

    #1

    Type.GetType

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

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

    Why?

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


  • Jon Skeet [C# MVP]

    #2
    Re: Type.GetType

    AlexS <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote:[color=blue]
    > I have app, which has usings for System.Windows. Forms
    >
    > But when I do Type.GetType("T reeView") or use full class name for TreeView
    > I get null.
    >
    > Why?
    >
    > Anything I miss? What are the rules of use for Type.GetType?[/color]

    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.GetTyp e, 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).

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • AlexS

      #3
      Re: Type.GetType

      Thanks for a hint

      I was able to get type using string
      "System.Windows .Forms.TreeView ,System.Windows .Forms, Version=1.0.500 0.0,
      Culture=neutral , PublicKeyToken= b77a5c561934e08 9"

      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

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1b7d26 e2485dc47198b0f 6@msnews.micros oft.com...[color=blue]
      > AlexS <salexru2000NO@ SPAMsympaticoPL EASE.ca> wrote:[color=green]
      > > I have app, which has usings for System.Windows. Forms
      > >
      > > But when I do Type.GetType("T reeView") or use full class name for[/color][/color]
      TreeView[color=blue][color=green]
      > > I get null.
      > >
      > > Why?
      > >
      > > Anything I miss? What are the rules of use for Type.GetType?[/color]
      >
      > 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.GetTyp e, 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).
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      Working...