Activator.CreateInstanceFrom Activator.CreateInstanceFrom Activator.CreateInstanceFrom Activator.CreateInstanceFrom Method

Definition

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

Overloads

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters.

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

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters.

CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[])

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.

CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String)

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and default constructor.

CreateInstanceFrom(String, String) CreateInstanceFrom(String, String) CreateInstanceFrom(String, String) CreateInstanceFrom(String, String)

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

Warning

This API is now obsolete.

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes, System::Security::Policy::Evidence ^ securityAttributes);
[System.Obsolete("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 CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityAttributes);
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle

Parameters

domain
AppDomain AppDomain AppDomain AppDomain

The remote domain where the type named typeName is created.

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

ignoreCase
Boolean Boolean Boolean Boolean

true to specify that the search for typeName is not case-sensitive; false to specify that the search is case-sensitive.

bindingAttr
BindingFlags BindingFlags BindingFlags 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
Binder Binder Binder Binder

An object that uses bindingAttr and args to seek and identify the typeName constructor. If binder is null, the default binder is used.

args
Object[]

An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. If culture is null, the CultureInfo for the current thread is used.

activationAttributes
Object[]

An array of one or more attributes that can participate in activation. This is 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.

securityAttributes
Evidence Evidence Evidence Evidence

Information used to make security policy decisions and grant code permissions.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Remarks

Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

Use the ObjectHandle.Unwrap method to unwrap the return value.

Note

This method uses SecurityAction.LinkDemand to require the immediate caller to have full trust.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

SecurityPermission
for supplying evidence. Associated enumeration: ControlEvidence

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types and members regardless of their grant set. Associated enumeration: MemberAccess

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

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

Warning

This API is now obsolete.

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes, System::Security::Policy::Evidence ^ securityInfo);
[System.Obsolete("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 CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityInfo);
static member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle

Parameters

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

ignoreCase
Boolean Boolean Boolean Boolean

true to specify that the search for typeName is not case-sensitive; false to specify that the search is case-sensitive.

bindingAttr
BindingFlags BindingFlags BindingFlags 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
Binder Binder Binder Binder

An object that uses bindingAttr and args to seek and identify the typeName constructor. If binder is null, the default binder is used.

args
Object[]

An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. If culture is null, the CultureInfo for the current thread is used.

activationAttributes
Object[]

An array of one or more attributes that can participate in activation. This is 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.

securityInfo
Evidence Evidence Evidence Evidence

Information used to make security policy decisions and grant code permissions.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Remarks

Use the ObjectHandle.Unwrap method to unwrap the return value.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

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

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types and members regardless of their grant set. Associated enumeration: MemberAccess

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes);
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle

Parameters

domain
AppDomain AppDomain AppDomain AppDomain

The remote domain where the type named typeName is created.

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

ignoreCase
Boolean Boolean Boolean Boolean

true to specify that the search for typeName is not case-sensitive; false to specify that the search is case-sensitive.

bindingAttr
BindingFlags BindingFlags BindingFlags 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
Binder Binder Binder Binder

An object that uses bindingAttr and args to seek and identify the typeName constructor. If binder is null, the default binder is used.

args
Object[]

An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. If culture is null, the CultureInfo for the current thread is used.

activationAttributes
Object[]

An array of one or more attributes that can participate in activation. This is 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.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile is not a valid assembly.

-or-

assemblyName was compiled for a version of the common language runtime that is later than the version that is currently loaded.

Remarks

Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

Use the ObjectHandle.Unwrap method to unwrap the return value.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions sections of the Assembly.LoadFrom and CreateInstance methods.

Security

SecurityPermission
for supplying evidence. Associated enumeration: ControlEvidence

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types and members regardless of their grant set. Associated enumeration: MemberAccess

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[]) CreateInstanceFrom(String, String, Object[])

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, cli::array <System::Object ^> ^ activationAttributes);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, object[] activationAttributes);
static member CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, activationAttributes As Object()) As ObjectHandle

Parameters

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

activationAttributes
Object[]

An array of one or more attributes that can participate in activation. This is 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.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Remarks

Use the ObjectHandle.Unwrap method to unwrap the return value.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

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

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types regardless of their grant set. Associated enumeration: MemberAccess

CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String) CreateInstanceFrom(AppDomain, String, String)

Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and default constructor.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName);
static member CreateInstanceFrom : AppDomain * string * string -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String) As ObjectHandle

Parameters

domain
AppDomain AppDomain AppDomain AppDomain

The remote domain where the type named typeName is created.

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Remarks

Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

Use the ObjectHandle.Unwrap method to unwrap the return value.

Note

This method uses SecurityAction.LinkDemand to require the immediate caller to have full trust.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

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

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

CreateInstanceFrom(String, String) CreateInstanceFrom(String, String) CreateInstanceFrom(String, String) CreateInstanceFrom(String, String)

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName);
static member CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String) As ObjectHandle

Parameters

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Examples

The following code example demonstrates how to call the CreateInstanceFrom method. This code example is part of a larger example provided for the Activator class.

// Create an instance of the SomeType class that is defined in this 
// assembly.
System::Runtime::Remoting::ObjectHandle^ oh = 
    Activator::CreateInstanceFrom(Assembly::GetEntryAssembly()->CodeBase, 
                                  SomeType::typeid->FullName);

// Call an instance method defined by the SomeType type using this object.
SomeType^ st = (SomeType^) oh->Unwrap();

st->DoSomething(5);
// Create an instance of the SomeType class that is defined in this 
// assembly.
System.Runtime.Remoting.ObjectHandle oh = 
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, 
                                 typeof(SomeType).FullName);

// Call an instance method defined by the SomeType type using this object.
SomeType st = (SomeType) oh.Unwrap();

st.DoSomething(5);
' Create an instance of the SomeType class that is defined in this assembly.
Dim oh As System.Runtime.Remoting.ObjectHandle = _
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, _
                                 GetType(SomeType).FullName)

' Call an instance method defined by the SomeType type using this object.
Dim st As SomeType = CType(oh.Unwrap(), SomeType)

st.DoSomething(5)

Remarks

Use the ObjectHandle.Unwrap method to unwrap the return value.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

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

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types regardless of their grant set. Associated enumeration: MemberAccess

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[]) CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes);
static member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle

Parameters

assemblyFile
String String String String

The name of a file that contains an assembly where the type named typeName is sought.

typeName
String String String String

The name of the preferred type.

ignoreCase
Boolean Boolean Boolean Boolean

true to specify that the search for typeName is not case-sensitive; false to specify that the search is case-sensitive.

bindingAttr
BindingFlags BindingFlags BindingFlags 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
Binder Binder Binder Binder

An object that uses bindingAttr and args to seek and identify the typeName constructor. If binder is null, the default binder is used.

args
Object[]

An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. If culture is null, the CultureInfo for the current thread is used.

activationAttributes
Object[]

An array of one or more attributes that can participate in activation. This is 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.

Returns

A handle that must be unwrapped to access the newly created instance.

Exceptions

The caller does not have permission to call this constructor.

Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism.

The constructor, which was invoked through reflection, threw an exception.

activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyName was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

Remarks

Use the ObjectHandle.Unwrap method to unwrap the return value.

For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

Security

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

FileIOPermission
for the ability to search directory paths and read their contents. Associated enumerations: PathDiscovery and Read

ReflectionPermission
for accessing nonpublic types and members regardless of their grant set. Associated enumeration: MemberAccess

Applies to