Assembly::CreateInstance Method (String^, Boolean)


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, with optional case-sensitive search.

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

virtual Object^ CreateInstance(
	String^ typeName,
	bool ignoreCase
) sealed


Type: System::String^

The Type::FullName of the type to locate.

Type: System::Boolean

true to ignore the case of the type name; otherwise, false.

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.


No matching constructor was found.


typeName is null.


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.

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

The following example defines a Person class. It then calls the CreateInstance(String^) method to instantiate it, but because the casing of the typeName argument doesn’t match that of the type's FullName property, the method returns null. When the example passes the same string to the CreateInstance(String^, Boolean) overload and specifies that the comparison should be case-insensitive, the Person class is found, and a Person object is successfully instantiated.

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


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

.NET Framework
Available since 1.1
Return to top