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

AppDomain::CreateInstanceAndUnwrap Method (String^, String^, Boolean, BindingFlags, Binder^, array<Object^>^, CultureInfo^, array<Object^>^, Evidence^)

obsoleteCodeEntityM:System.AppDomain.CreateInstanceAndUnwrap(System.String,System.String,System.Boolean,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object[],System.Globalization.CultureInfo,System.Object[])Note: This API is now obsolete.

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)

[ObsoleteAttribute("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceAndUnwrap which does not take an Evidence parameter. See for more information.")]
Object^ CreateInstanceAndUnwrap(
	String^ assemblyName,
	String^ typeName,
	bool ignoreCase,
	BindingFlags bindingAttr,
	Binder^ binder,
	array<Object^>^ args,
	CultureInfo^ culture,
	array<Object^>^ activationAttributes,
	Evidence^ securityAttributes


Type: System::String^

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

Type: System::String^

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

Type: System::Boolean

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

Type: System.Reflection::BindingFlags

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.

Type: System.Reflection::Binder^

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.

Type: array<System::Object^>^

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.

Type: System.Globalization::CultureInfo^

A culture-specific object used to govern the coercion of types. If culture is null, the CultureInfo for the current thread is used.

Type: array<System::Object^>^

An array of one or more attributes that can participate in activation. Typically, an array that contains a single UrlAttribute object that specifies the URL that is required to activate a remote object.

This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation.

Type: System.Security.Policy::Evidence^

Information used to authorize creation of typeName.

Return Value

Type: System::Object^

An instance of the object specified by typeName.

Exception Condition

assemblyName or typeName is null.


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.


The operation is attempted on an unloaded application domain.


assemblyName is not a valid assembly.


Version 2.0 or later of the common language runtime is currently loaded and assemblyName was compiled with a later version.


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

This is a convenience method that combines CreateInstance and ObjectHandle::Unwrap.

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 namespace System;
using namespace System::Reflection;
static void InstantiateINT32( bool ignoreCase )
      AppDomain^ currentDomain = AppDomain::CurrentDomain;
      Object^ instance = currentDomain->CreateInstanceAndUnwrap( 
         "mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089", 
         nullptr );
      Console::WriteLine( instance->GetType() );
   catch ( TypeLoadException^ e ) 
      Console::WriteLine( e->Message );


int main()
   InstantiateINT32( false ); // Failed!
   InstantiateINT32( true ); // OK!


for the ability to access the location of the assembly. Associated enumeration: FileIOPermissionAccess::PathDiscovery


for the ability to read the file containing the assembly manifest. Associated enumeration: FileIOPermissionAccess::Read


for the ability to access the location of the assembly if the assembly is not local.


for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag::UnmanagedCode


to load an assembly with evidence. Associated enumeration: SecurityPermissionFlag::ControlEvidence.


for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag::MemberAccess

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft