ערוך

שתף באמצעות


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

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
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.

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[])

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

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 parameterless constructor.

CreateInstanceFrom(String, String)

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

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)

Caution

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.

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);
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);
[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
[<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>]
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
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object(), securityAttributes As Evidence) As ObjectHandle

Parameters

domain
AppDomain

The remote domain where the type named typeName is created.

assemblyFile
String

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

typeName
String

The name of the type to create an instance of.

ignoreCase
Boolean

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

bindingAttr
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

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 parameterless constructor) is invoked.

culture
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

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

Returns

A handle that must be unwrapped to access the newly created object, or null for Nullable<T> instances.

Attributes

Exceptions

domain or typeName is null.

No matching constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does have the required FileIOPermission.

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

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

Applies to

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

Caution

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.

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);
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);
[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
[<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.")>]
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
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object(), securityInfo As Evidence) As ObjectHandle

Parameters

assemblyFile
String

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

typeName
String

The name of the type to create an instance of.

ignoreCase
Boolean

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

bindingAttr
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

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 parameterless constructor) is invoked.

culture
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

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

Returns

A handle that must be unwrapped to access the newly created object, or null for Nullable<T> instances.

Attributes

Exceptions

typeName is null.

No matching constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does not have the required FileIOPermission.

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

Applies to

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);
[<System.Security.SecurityCritical>]
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object()) As ObjectHandle

Parameters

domain
AppDomain

The remote domain where the type named typeName is created.

assemblyFile
String

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

typeName
String

The name of the type to create an instance of.

ignoreCase
Boolean

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

bindingAttr
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

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 parameterless constructor) is invoked.

culture
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 object, or null for Nullable<T> instances.

Attributes

Exceptions

domain or typeName is null.

No matching constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does have the required FileIOPermission.

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

assemblyFile is not a valid assembly.

-or-

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

Applies to

CreateInstanceFrom(String, String, Object[])

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

Creates an instance of the type whose name is specified, using the named assembly file and parameterless 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);
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

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

typeName
String

The name of the type to create an instance of.

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 object, or null for Nullable<T> instances.

Exceptions

typeName is null.

No matching public constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does have the required FileIOPermission.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyFile 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.

Applies to

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 parameterless constructor.

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, 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
[<System.Security.SecurityCritical>]
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

The remote domain where the type named typeName is created.

assemblyFile
String

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

typeName
String

The name of the type to create an instance of.

Returns

A handle that must be unwrapped to access the newly created object, or null for Nullable<T> instances.

Attributes

Exceptions

domain or typeName is null.

No matching public constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does have the required FileIOPermission.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyFile 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.

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

Applies to

CreateInstanceFrom(String, String)

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

Creates an instance of the type whose name is specified, using the named assembly file and parameterless 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);
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

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

typeName
String

The name of the type to create an instance of.

Returns

A handle that must be unwrapped to access the newly created object, or null for Nullable<T> instances.

Exceptions

typeName is null.

No matching public constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does have the required FileIOPermission.

assemblyFile is not a valid assembly.

-or-

The common language runtime (CLR) version 2.0 or later is currently loaded, and assemblyFile 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.
let oh = 
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().Location, typeof<SomeType>.FullName)

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

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.

Applies to

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

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

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);
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
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object()) As ObjectHandle

Parameters

assemblyFile
String

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

typeName
String

The name of the type to create an instance of.

ignoreCase
Boolean

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

bindingAttr
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

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 parameterless constructor) is invoked.

culture
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 object, or null for Nullable<T> instances.

Exceptions

typeName is null.

No matching constructor was found.

typeName was not found in assemblyFile.

assemblyFile was not found.

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.

The caller does not have the required FileIOPermission.

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

Applies to