Using Reflection and Type.GetType

Recently I had to use Type.GetType to use Remote Objects in IIS (yea its old) and I kept running into a problem with Type.GetType("...") returning null.

So after trying and trying and rechecking my spelling over and over, I discovered this article.

http://blogs.msdn.com/haibo_luo/archive/2005/08/21/454213.aspx

 

Moral of the story - Type.GetType(<string>) will only search inside of the current assembly.  To get this to work use:

Type.GetType(typeof(<object>).AssemblyQualifiedName)

 

ex: 

   31             RemoteObject obj;

   32             obj = (RemoteObject)Activator.GetObject(Type.GetType(typeof(RemoteObject).AssemblyQualifiedName), "http://localhost:4736/RemoteObject.rem");

7 Comments

  • The only difference between:
    Type.GetType(typeof().AssemblyQualifiedName)

    and:
    typeof()

    is that the second statement will be considerably faster, and is easier to read.

    Your code can be written as:
    RemoveObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "http://localhost:4736/RemoteObject.rem");

  • I visited tons of website but I believe this one has got something extra
    in it in it

  • *Nice post. I find some thing much harder on a range of internet websites everyday.
    Most commonly it is stimulating to study content out of other writers and exercise a specific
    thing out of their website. I’d opt to apply certain while using that the content in this minor blog whether you do not mind.
    Natually I’ll give a link on your own internet weblog.
    Appreciate your sharing.

  • i love bloghoping and i actually love to comment on
    your blog.

  • I’d always would something like to be update on new articles on this web site ,
    saved to favorites ! .

  • Thus you wish efficient over the internet income ideas for keep present in setting aside
    time for tips appropriate for very own web-based marketing.
    Inernet marketing

  • I discovered your blog post site on google and check a couple of
    of your early posts. Always keep in the great operate.
    I only extra the RSS feed to my MSN News Reader.
    Searching for toward reading much more on your part at a later
    date!…

Comments have been disabled for this content.