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

Note: This API is now obsolete. The non-obsolete alternative is CreateInstanceAndUnwrap.

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(L"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 http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public:
Object^ CreateInstanceAndUnwrap(
	String^ assemblyName, 
	String^ typeName, 
	bool ignoreCase, 
	BindingFlags bindingAttr, 
	Binder^ binder, 
	array<Object^>^ args, 
	CultureInfo^ culture, 
	array<Object^>^ activationAttributes, 
	Evidence^ securityAttributes
)

Parameters

assemblyName
Type: System::String

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

typeName
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.

ignoreCase
Type: System::Boolean

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

bindingAttr
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.

binder
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.

args
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.

culture
Type: System.Globalization::CultureInfo

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

activationAttributes
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. The UrlAttribute specifies the URL that is required to activate a remote object.

securityAttributes
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.

ExceptionCondition
ArgumentNullException

assemblyName or typeName is nullptr.

MissingMethodException

No matching constructor was found.

TypeLoadException

typename was not found in assemblyName.

FileNotFoundException

assemblyName was not found.

MethodAccessException

The caller does not have permission to call this constructor.

NotSupportedException

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

AppDomainUnloadedException

The operation is attempted on an unloaded application domain.

BadImageFormatException

assemblyName is not a valid assembly.

-or-

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

FileLoadException

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.

The activationAttributes parameter is related to client-activated objects; see Client Activation.

NoteNote

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 )
{
   try
   {
      AppDomain^ currentDomain = AppDomain::CurrentDomain;
      Object^ instance = currentDomain->CreateInstanceAndUnwrap( 
         "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 
         "SYSTEM.INT32", 
         ignoreCase, 
         BindingFlags::Default, 
         nullptr, 
         nullptr, 
         nullptr, 
         nullptr, 
         nullptr );
      Console::WriteLine( instance->GetType() );
   }
   catch ( TypeLoadException^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Obsolete (compiler warning) in 4.5.2
Obsolete (compiler warning) in 4.5.1
Obsolete (compiler warning) in 4.5
Obsolete (compiler warning) in 4

.NET Framework Client Profile

Supported in: 3.5 SP1
Obsolete (compiler warning) in 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft