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");

Published Friday, October 17, 2008 8:36 PM by Kiyoshi

Comments

# re: Using Reflection and Type.GetType

Tuesday, October 21, 2008 2:46 PM by RichardD

The only difference between:

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

and:

typeof(<object>)

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), "localhost/RemoteObject.rem");

Leave a Comment

(required) 
(required) 
(optional)
(required)