Welcome to MSDN Blogs Sign in | Join | Help

Using Type.GetType(typeName)

If no assembly is specified, Type.GetType() will only look in the calling assembly and then mscorlib.dll for the type. For it to look in any other assembly, you need to give the Type.AssemblyQualifiedName for the type. For example:

Type.GetType("System.Uri, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

This is because part of the type identity is its assembly. We don't check for it in all of the assemblies in the appdomain because (a) that would be bad for performance and (b) it's legal to use multiple types with the same name, but from different assemblies. In that case, we wouldn't know which one is the right one to return. So, it's always required to specify the assembly or else we will only make limited guesses.

Of course, if you would rather not supply the assembly display name, you can call Assembly.GetType() or typeof() instead.

Published Friday, May 30, 2003 12:34 AM by Suzanne Cook
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Using Type.GetType(typeName)

Is there a way to specify which assembly but not which version? I'm using reflection to get at InputPanel in Microsoft.WindowsCE.Forms in the compact framework while keeping desktop execution working, and I want a way to say "get this type from this dll or any newer version." It works for the CF installed on one of my PocketPC's, but not the other, presumably because of a newer CF.
Monday, June 07, 2004 11:28 AM by Andrew

# re: Using Type.GetType(typeName)

Hello,

Is it possible to load a Type which is located in an assembly which is not in the bin folder from the value previously retrieved from Type.AssemblyQualifiedName.
Ex :
/webapp/plugins/TestPlugin1.dll

load the Class1 into TestPlugin1.dll
from the string
TestPlugin1.Class1, TestPlugin1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Thanks in advance for your help
Christophe

Tuesday, February 21, 2006 7:26 AM by chris.katsuo

# re: Using Type.GetType(typeName)

The royal WE is being used above indicating your on that team that owns this feature.  Shouldn't the above comments be part of the docs on msdn?  I don't seem to see them http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtypeclassgettypetopic1.asp
Tuesday, June 27, 2006 5:55 PM by Jordan Sehn

# Type.GetType(typeName)

Dear (royal) Suzanne

This post was very helpful for me. Now, in this second, I debug my Visual Studio Package and have this assembly layout:

Package

--> Language

   --> BunnyCore.dll in GAC !!!

In the Language assembly I say

Type t = Type.GetType("Carrots.Bunny");

so fulltypename but no assembly is given, and I get back the correct type that refers to the assembly in the GAC !??

Considering your (reasonable) algorithm above, I should get null. Thank you for clarification.

Friday, July 18, 2008 6:23 PM by citykid

# Putting Anything in a Cell? - Custom Editor Provider for WebDataGrid

Have you already considered the RowEditTemplate and Templated Column features but would rather use a

Tuesday, March 17, 2009 11:13 AM by Sung Kim

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker