Assembly.CreateInstance Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Locates the specified type from this assembly and creates an instance of it using the system activator, using case-sensitive search.

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

public object CreateInstance(
	string typeName


Type: System.String

The Type.FullName of the type to locate.

Return Value

Type: System.Object

An instance of the specified type created with the default constructor; or null if typeName is not found. The type is resolved using the default binder, without specifying culture or activation attributes, and with BindingFlags set to Public or Instance.

Exception Condition

typeName is an empty string ("") or a string beginning with a null character.


The current assembly was loaded into the reflection-only context.


typeName is null.


No matching constructor was found.


typeName requires a dependent assembly that could not be found.


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


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


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


typeName requires a dependent assembly that was compiled for a version of the runtime that is later than the currently loaded version.

If the runtime is unable to find typeName in the Assembly instance, it returns null instead of throwing an exception. This might happen because:

  • You haven't specified the fully qualified name of the type.

  • You've specified the fully qualified type name, but its case doesn’t match the case of the type's Type.FullName property. For a case-insensitive comparison of typeName with the type's full name, call the CreateInstance(String, Boolean) overload and specify true for the ignoreCase argument.

  • The type doesn’t exist in the current Assembly instance.

The following example defines a Person class and calls the CreateInstance(String) method to instantiate it.

using System;
using System.Reflection;
using Contoso.Libraries;

namespace Contoso.Libraries
   public class Person
      private string _name;

      public Person()
      { }

      public Person(string name)
         this._name = name;

      public string Name
      { get { return this._name; }
        set { this._name = value; } }

      public override string ToString()
         return this._name;

public class Example
   public static void Main()
      Assembly assem = typeof(Person).Assembly;
      Person p = (Person) assem.CreateInstance("Contoso.Libraries.Person");
      if (! (p == null)) {
         p.Name = "John";
         Console.WriteLine("Instantiated a {0} object whose value is '{1}'",
                           p.GetType().Name, p);
      else {
         Console.WriteLine("Unable to instantiate a Person object.");
// The example displays the following output:
//        Instantiated a Person object whose value is 'John'


when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess

.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top