AppDomain.CreateInstanceAndUnwrap Method (String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

Creates a new instance of the specified type. Parameters specify the name of the type, and how it is found and created.

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

public Object CreateInstanceAndUnwrap (
	string assemblyName,
	string typeName,
	bool ignoreCase,
	BindingFlags bindingAttr,
	Binder binder,
	Object[] args,
	CultureInfo culture,
	Object[] activationAttributes,
	Evidence securityAttributes
public Object CreateInstanceAndUnwrap (
	String assemblyName, 
	String typeName, 
	boolean ignoreCase, 
	BindingFlags bindingAttr, 
	Binder binder, 
	Object[] args, 
	CultureInfo culture, 
	Object[] activationAttributes, 
	Evidence securityAttributes
public function CreateInstanceAndUnwrap (
	assemblyName : String, 
	typeName : String, 
	ignoreCase : boolean, 
	bindingAttr : BindingFlags, 
	binder : Binder, 
	args : Object[], 
	culture : CultureInfo, 
	activationAttributes : Object[], 
	securityAttributes : Evidence
) : Object



The display name of the assembly. See Assembly.FullName.


The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the Type.FullName property.


A Boolean value specifying whether to perform a case-sensitive search or not.


A combination of zero or more bit flags that affect the search for the typeName constructor. If bindingAttr is zero, a case-sensitive search for public constructors is conducted.


An object that enables the binding, coercion of argument types, invocation of members, and retrieval of MemberInfo objects using reflection. If binder is null, the default binder is used.


The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the default constructor is preferred, args must be an empty array or null.


A culture-specific object used to govern the coercion of types. If culture is a null reference (Nothing in Visual Basic), the CultureInfo for the current thread is used.


An array of one or more attributes that can participate in activation.


Information used to authorize creation of typeName.

Return Value

An instance of the object specified by typeName.

Exception typeCondition


assemblyName or typeName is a null reference (Nothing in Visual Basic).


No matching constructor was found.


typename was not found in assemblyName.


assemblyName was not found.


The caller does not have permission to call this constructor.


The caller cannot provide activation attributes for an object that does not inherit from MarshalByRefObject.


Operations are attempted on an unloaded application domain.


assemblyName is not a valid assembly.


An assembly or module was loaded twice with two different evidences.

This is a convenience method that combines CreateInstance and ObjectHandle.Unwrap. This method calls the default constructor for typeName.

See AssemblyName for the format of assemblyName. See the Type.FullName property for the format of typeName.


If you make an early-bound call to a method M of an object of type T1 that was returned by CreateInstanceAndUnwrap, and that method makes an early-bound call to a method of an object of type T2 in an assembly C other than the current assembly or the assembly containing T1, assembly C is loaded into the current application domain. This loading occurs even if the early-bound call to T1.M() was made in the body of a DynamicMethod, or in other dynamically generated code. If the current domain is the default domain, assembly C cannot be unloaded until the process ends. If the current domain later attempts to load assembly C, the load might fail.

The following sample demonstrates the use of the ignoreCase parameter.

using System;
using System.Reflection;

class Test {

   static void Main() {
      InstantiateINT32(false);     // Failed!
      InstantiateINT32(true);      // OK!
   static void InstantiateINT32(bool ignoreCase) {
      try {
         AppDomain currentDomain = AppDomain.CurrentDomain;
         object instance = currentDomain.CreateInstanceAndUnwrap(
      } catch (TypeLoadException e) {

import System.*;
import System.Reflection.*;

class Test
    public static void main(String[] args)
        InstantiateInt32(false); // Failed!
        InstantiateInt32(true); // OK!
    } //main

    static void InstantiateInt32(boolean ignoreCase)
        try {
            AppDomain currentDomain = AppDomain.get_CurrentDomain();
            Object instance = currentDomain.CreateInstanceAndUnwrap("mscorlib", 
                "SYSTEM.INT32", ignoreCase, BindingFlags.Default, 
                null, null, null, null, null);
        catch (TypeLoadException e) {
    } //InstantiateInt32
} //Test

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions