GetType Method (String)

Assembly.GetType Method (String)

 

Gets the Type object with the specified name in the assembly instance.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

abstract GetType : 
        name:string -> Type
override GetType : 
        name:string -> Type

Parameters

name
Type: System.String

The full name of the type.

Return Value

Type: System.Type

An object that represents the specified class, or null if the class is not found.

Exception Condition
ArgumentException

name is invalid.

ArgumentNullException

name is null.

FileNotFoundException

name requires a dependent assembly that could not be found.

FileLoadException
System_CAPS_noteNote

In the .NET for Windows Store apps or the , catch the base class exception, IOException, instead.

name requires a dependent assembly that was found but could not be loaded.

-or-

The current assembly was loaded into the reflection-only context, and name requires a dependent assembly that was not preloaded.

BadImageFormatException

name requires a dependent assembly, but the file is not a valid assembly.

-or-

name requires a dependent assembly which was compiled for a version of the runtime later than the currently loaded version.

This method only searches the current assembly instance. The name parameter includes the namespace but not the assembly. To search other assemblies for a type, use the Type.GetType(String) method overload, which can optionally include an assembly display name as part of the type name.

System_CAPS_noteNote

If the type has been forwarded to another assembly, it is still returned by this method. For information on type forwarding, see Type Forwarding in the Common Language Runtime.

The following example defines an abstract MeansOfTransportation class in the Transportation namespace. It calls the GetType(String) method to retrieve its Type object, calls the Type.GetProperties method to get an array of PropertyInfo objects that represent the type's properties, and then displays information on the type's abstract properties. Note that the call to the GetType(String) method uses the type's fully qualified name (that is, its namespace along with its type name).

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft