Activator.CreateInstanceFrom 方法
定义
使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。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) |
已过时。
使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。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) |
已过时。
使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。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)
注意
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
参数
- domain
- AppDomain
在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 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
影响 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
使用 bindingAttr 和 args 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 binder 为 null,则使用默认联编程序。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 parameterless constructor) is invoked.
- culture
- CultureInfo
区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culture 为 null,则使用当前线程的 CultureInfo。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. 这通常为包含单个 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
用于做出安全策略决策和授予代码权限的信息。Information used to make security policy decisions and grant code permissions.
返回
要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.
- 属性
例外
domain 或 typeName 为 null。domain or typeName is null.
未找到匹配的构造函数。No matching constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方确实具有所需的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.
适用于
CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
注意
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
参数
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 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
影响 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
使用 bindingAttr 和 args 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 binder 为 null,则使用默认联编程序。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 parameterless constructor) is invoked.
- culture
- CultureInfo
区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culture 为 null,则使用当前线程的 CultureInfo。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. 这通常为包含单个 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
用于做出安全策略决策和授予代码权限的信息。Information used to make security policy decisions and grant code permissions.
返回
要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.
- 属性
例外
typeName 为 null。typeName is null.
未找到匹配的构造函数。No matching constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方没有所要求的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.
适用于
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
参数
- domain
- AppDomain
在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 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
影响 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
使用 bindingAttr 和 args 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 binder 为 null,则使用默认联编程序。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 parameterless constructor) is invoked.
- culture
- CultureInfo
区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culture 为 null,则使用当前线程的 CultureInfo。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. 这通常为包含单个 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.
- 属性
例外
domain 或 typeName 为 null。domain or typeName is null.
未找到匹配的构造函数。No matching constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方确实具有所需的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions sections of the Assembly.LoadFrom and CreateInstance methods.
适用于
CreateInstanceFrom(String, String, Object[])
使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。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
参数
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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. 这通常为包含单个 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.
例外
typeName 为 null。typeName is null.
未找到匹配的公共构造函数。No matching public constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。activationAttributes is not an empty array, and the type being created does not derive from MarshalByRefObject.
调用方确实具有所需的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.
适用于
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
参数
- domain
- AppDomain
在其中创建名为 typeName 的类型的远程域。The remote domain where the type named typeName is created.
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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.
返回
要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.
- 属性
例外
domain 或 typeName 为 null。domain or typeName is null.
未找到匹配的公共构造函数。No matching public constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方确实具有所需的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.
适用于
CreateInstanceFrom(String, String)
使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。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
参数
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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.
返回
要访问新创建的实例则必须解包的句柄。A handle that must be unwrapped to access the newly created instance.
例外
typeName 为 null。typeName is null.
未找到匹配的公共构造函数。No matching public constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方确实具有所需的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.
适用于
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);
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
参数
- assemblyFile
- String
包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。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 指定对 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
影响 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
使用 bindingAttr 和 args 来查找和标识 typeName 构造函数的对象。An object that uses bindingAttr and args to seek and identify the typeName constructor. 如果 binder 为 null,则使用默认联编程序。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 parameterless constructor) is invoked.
- culture
- CultureInfo
区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。Culture-specific information that governs the coercion of args to the formal types declared for the typeName constructor. 如果 culture 为 null,则使用当前线程的 CultureInfo。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. 这通常为包含单个 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.
例外
typeName 为 null。typeName is null.
未找到匹配的构造函数。No matching constructor was found.
在 assemblyFile 中未找到 typename。typename was not found in assemblyFile.
未找到 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.
调用方没有所要求的 FileIOPermission。The 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.LoadFrom CreateInstance 。For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the Assembly.LoadFrom and CreateInstance methods.