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

定义

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。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)

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。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)

警告

此 API 现已过时。

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。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

参数

domain
AppDomain AppDomain AppDomain AppDomain

在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。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

影响 typeName 构造函数搜索的零个或多个位标志的组合。A combination of zero or more bit flags that affect the search for the typeName constructor. 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder
Binder Binder Binder Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 bindernull,则使用默认联编程序。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. 如果 args 为空数组或 null,则调用不带任何参数的构造函数(默认构造函数)。If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culturenull,则使用当前线程的 CultureInfoIf 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. 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。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. 应改用 Windows Communication Foundation 来开发分布式应用程序。Distributed applications should instead use Windows Communication Foundation.

securityAttributes
Evidence Evidence Evidence Evidence

用于做出安全策略决策和授予代码权限的信息。Information used to make security policy decisions and grant code permissions.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

domaintypeNamenulldomain or typeName is null.

未找到匹配的构造函数。No matching constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方确实具有所需的 FileIOPermissionThe caller does have the required FileIOPermission.

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

注解

使用CreateInstanceFrom主机需要具有受限的安全权限的应用程序域中执行代码。Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

备注

此方法使用SecurityAction.LinkDemand需要直接调用方具有完全信任。This method uses SecurityAction.LinkDemand to require the immediate caller to have full trust.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
为提供证据。for supplying evidence. 关联的枚举: ControlEvidenceAssociated enumeration: ControlEvidence

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型和成员而不考虑其授予集。for accessing nonpublic types and members regardless of their grant set. 关联的枚举: MemberAccessAssociated 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)

警告

此 API 现已过时。

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。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

参数

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。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

影响 typeName 构造函数搜索的零个或多个位标志的组合。A combination of zero or more bit flags that affect the search for the typeName constructor. 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder
Binder Binder Binder Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 bindernull,则使用默认联编程序。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. 如果 args 为空数组或 null,则调用不带任何参数的构造函数(默认构造函数)。If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culturenull,则使用当前线程的 CultureInfoIf 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. 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。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. 应改用 Windows Communication Foundation 来开发分布式应用程序。Distributed applications should instead use Windows Communication Foundation.

securityInfo
Evidence Evidence Evidence Evidence

用于做出安全策略决策和授予代码权限的信息。Information used to make security policy decisions and grant code permissions.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

未找到匹配的构造函数。No matching constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方没有所要求的 FileIOPermissionThe caller does not have the required FileIOPermission.

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

注解

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
表示创建委托的实例时调用非托管的代码的能力。for the ability to call unmanaged code when creating an instance of a delegate. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型和成员而不考虑其授予集。for accessing nonpublic types and members regardless of their grant set. 关联的枚举: MemberAccessAssociated 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

参数

domain
AppDomain AppDomain AppDomain AppDomain

在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。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

影响 typeName 构造函数搜索的零个或多个位标志的组合。A combination of zero or more bit flags that affect the search for the typeName constructor. 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder
Binder Binder Binder Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 bindernull,则使用默认联编程序。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. 如果 args 为空数组或 null,则调用不带任何参数的构造函数(默认构造函数)。If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culturenull,则使用当前线程的 CultureInfoIf 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. 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。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. 应改用 Windows Communication Foundation 来开发分布式应用程序。Distributed applications should instead use Windows Communication Foundation.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

domaintypeNamenulldomain or typeName is null.

未找到匹配的构造函数。No matching constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方确实具有所需的 FileIOPermissionThe caller does have the required FileIOPermission.

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- assemblyName 是针对晚于当前加载版本的公共语言运行时版本编译的。assemblyName was compiled for a version of the common language runtime that is later than the version that is currently loaded.

注解

使用CreateInstanceFrom主机需要具有受限的安全权限的应用程序域中执行代码。Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions sections of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
为提供证据。for supplying evidence. 关联的枚举: ControlEvidenceAssociated enumeration: ControlEvidence

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型和成员而不考虑其授予集。for accessing nonpublic types and members regardless of their grant set. 关联的枚举: MemberAccessAssociated 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

参数

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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. 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。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. 应改用 Windows Communication Foundation 来开发分布式应用程序。Distributed applications should instead use Windows Communication Foundation.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

未找到匹配的公共构造函数。No matching public constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

调用方确实具有所需的 FileIOPermissionThe caller does have the required FileIOPermission.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

注解

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
表示创建委托的实例时调用非托管的代码的能力。for the ability to call unmanaged code when creating an instance of a delegate. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型,而不考虑其授予集。for accessing nonpublic types regardless of their grant set. 关联的枚举: MemberAccessAssociated 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

参数

domain
AppDomain AppDomain AppDomain AppDomain

在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

domaintypeNamenulldomain or typeName is null.

未找到匹配的公共构造函数。No matching public constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方确实具有所需的 FileIOPermissionThe caller does have the required FileIOPermission.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

注解

使用CreateInstanceFrom主机需要具有受限的安全权限的应用程序域中执行代码。Use CreateInstanceFrom when a host needs to execute code in an application domain that has restricted security permissions.

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

备注

此方法使用SecurityAction.LinkDemand需要直接调用方具有完全信任。This method uses SecurityAction.LinkDemand to require the immediate caller to have full trust.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
表示创建委托的实例时调用非托管的代码的能力。for the ability to call unmanaged code when creating an instance of a delegate. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated 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

参数

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

未找到匹配的公共构造函数。No matching public constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方确实具有所需的 FileIOPermissionThe caller does have the required FileIOPermission.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

示例

下面的代码示例演示如何调用CreateInstanceFrom方法。The following code example demonstrates how to call the CreateInstanceFrom method. 此代码示例是为提供一个更大示例的一部分Activator类。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)

注解

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
表示创建委托的实例时调用非托管的代码的能力。for the ability to call unmanaged code when creating an instance of a delegate. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型,而不考虑其授予集。for accessing nonpublic types regardless of their grant set. 关联的枚举: MemberAccessAssociated 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

参数

assemblyFile
String String String String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。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

影响 typeName 构造函数搜索的零个或多个位标志的组合。A combination of zero or more bit flags that affect the search for the typeName constructor. 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder
Binder Binder Binder Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 bindernull,则使用默认联编程序。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. 如果 args 为空数组或 null,则调用不带任何参数的构造函数(默认构造函数)。If args is an empty array or null, the constructor that takes no parameters (the default constructor) is invoked.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culturenull,则使用当前线程的 CultureInfoIf 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. 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。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. 应改用 Windows Communication Foundation 来开发分布式应用程序。Distributed applications should instead use Windows Communication Foundation.

返回

要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.

异常

未找到匹配的构造函数。No matching constructor was found.

assemblyFile 中未找到 typenametypename was not found in assemblyFile.

未找到 assemblyFileassemblyFile 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.

调用方没有所要求的 FileIOPermissionThe caller does not have the required FileIOPermission.

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.

assemblyFile 不是有效的程序集。assemblyFile is not a valid assembly.

- 或 --or- 当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。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. 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0.

注解

使用ObjectHandle.Unwrap方法来打开返回的值。Use the ObjectHandle.Unwrap method to unwrap the return value.

有关可由被调用的方法引发其他异常信息,请参阅的异常部分Assembly.LoadFromCreateInstance方法。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.

安全性

SecurityPermission
表示创建委托的实例时调用非托管的代码的能力。for the ability to call unmanaged code when creating an instance of a delegate. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

FileIOPermission
为目录路径中搜索和读取其内容的功能。for the ability to search directory paths and read their contents. 关联枚举:PathDiscoveryReadAssociated enumerations: PathDiscovery and Read

ReflectionPermission
用于访问非公共类型和成员而不考虑其授予集。for accessing nonpublic types and members regardless of their grant set. 关联的枚举: MemberAccessAssociated enumeration: MemberAccess

适用于