System.Activator Class

Assembly: Mscorlib.dll
Namespace: System
Summary
Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects.
C# Syntax:
public sealed class Activator
Remarks
The Activator.CreateInstance method creates an instance of a type defined in an assembly by invoking the constructor that best matches the specified arguments. If no arguments are specified then the constructor that takes no parameters, that is, the default constructor, is invoked.

You must have sufficient permission to search for and call a constructor, otherwise and exception is thrown. By default, only public constructors are considered during the search for a constructor. If no constructor or default constructor can be found, an exception is thrown.

A binder parameter specifies an object that searches an assembly for a suitable constructor. You can specify your own binder and search criteria, but if no binder is specified a default binder is used. For more information, see the Binder and BindingFlags classes.

An evidence parameter affects the security policy and permissions for the constructor. For more information, see the Evidence class.

An instance of a type can be created at a local or remote site. If the type is created remotely, an activation attribute parameter specifies the URI of the remote site. The call to create the instance might pass through intermediary sites before it reaches the remote site. Other activation attributes can modify the environment, or context, in which the call operates at the remote and intermediary sites.

If the instance is created locally, a reference to that object is returned. If the instance is created remotely, a reference to a proxy is returned. The remote object is manipulated through the proxy as if it were a local object.

The Activator.GetObject method creates a proxy to a currently running remote object, server-activated well-known object, or XML Web service. You can specify the connection medium, that is, the channel. For more information, see the ChannelServices class.

Assemblies contain type definitions. The Activator.CreateInstance method creates an instance of a type from a currently running assembly. The Activator.CreateInstanceFrom method creates an instance from a file that contains an assembly. The System.Activator.CreateComInstanceFrom (not supported on the shared source CLI) method creates an instance of a COM object from a file that contains an assembly.

For more information about server-activated and client-activated objects, see the the conceptual topic at MSDN: serveractivation topic.

See also:
System Namespace

System.Activator Member List:

Public Methods
CreateInstance Overloaded:
CreateInstance(Type type)

Creates an instance of the specified type using the constructor that best matches the specified parameter.
CreateInstance Overloaded:
CreateInstance(string assemblyName, string typeName)

Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the default constructor.
CreateInstance Overloaded:
CreateInstance(Type type, bool nonPublic)

Creates an instance of the specified type using the constructor that best matches the specified parameter.
CreateInstance Overloaded:
CreateInstance(Type type, object[] args)

Creates an instance of the specified type using the constructor that best matches the specified parameters.
CreateInstance Overloaded:
CreateInstance(string assemblyName, string typeName, object[] activationAttributes)

Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the default constructor.
CreateInstance Overloaded:
CreateInstance(Type type, object[] args, object[] activationAttributes)

Creates an instance of the specified type using the constructor that best matches the specified parameters.
CreateInstance Overloaded:
CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture)

Creates an instance of the specified type using the constructor that best matches the specified parameters.
CreateInstance Overloaded:
CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)

Creates an instance of the specified type using the constructor that best matches the specified parameters.
CreateInstance Overloaded:
CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)

Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the specified parameters.
CreateInstanceFrom Overloaded:
CreateInstanceFrom(string assemblyFile, string typeName)

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.
CreateInstanceFrom Overloaded:
CreateInstanceFrom(string assemblyFile, string typeName, object[] activationAttributes)

Creates an instance of the type whose name is specified, using the named assembly file and default constructor.
CreateInstanceFrom Overloaded:
CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)

Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetObject Overloaded:
GetObject(Type type, string url)

Creates a proxy for the well-known object indicated by the specified type and URL.
GetObject Overloaded:
GetObject(Type type, string url, object state)

Creates a proxy for the well-known object indicated by the specified type, URL, and channel data.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Activator Member Details

Overloaded Method: CreateInstance(
   Type type
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameter.
C# Syntax:
public static object CreateInstance(
   Type type
);
Parameters:

type

The type of object to create.

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible.
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   string assemblyName,
   string typeName
)
Summary
Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the default constructor.
C# Syntax:
public static ObjectHandle CreateInstance(
   string assemblyName,
   string typeName
);
Parameters:

assemblyName

The name of the assembly where the type named typeName is sought. If assemblyName is null, the executing assembly is searched.

typeName

The name of the preferred type.

Return Value:
A handle that must be unwrapped to access the newly created instance.
Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching public constructor was found.
TypeLoadException typename was not found in assemblyName.
FileNotFoundException assemblyName was not found.
MethodAccessException The caller does not have permission to call this constructor.
TargetInvocationException The constructor, which was invoked through reflection, threw an exception.
Remarks
This method allows objects to be created remotely without having to load the type locally.

Use ObjectHandle.Unwrap to unwrap the return value.

.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   Type type,
   bool nonPublic
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameter.
C# Syntax:
public static object CreateInstance(
   Type type,
   bool nonPublic
);
Parameters:

type

The type of object to create.

nonPublic

true if a matching, parameterless constructor can be public or not public; otherwise, only a public constructor can match.

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible.
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   Type type,
   object[] args
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameters.
C# Syntax:
public static object CreateInstance(
   Type type,
   object[] args
);
Parameters:

type

The type of object to create.

args

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

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible and provide the most specific match with the specified argument list.
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   string assemblyName,
   string typeName,
   object[] activationAttributes
)
Summary
Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the default constructor.
C# Syntax:
public static ObjectHandle CreateInstance(
   string assemblyName,
   string typeName,
   object[] activationAttributes
);
Parameters:

assemblyName

The name of the assembly where the type named typeName is sought. If assemblyName is null, the executing assembly is searched.

typeName

The name of the preferred type.

activationAttributes

An array of one or more attributes that can participate in activation.

Return Value:
A handle that must be unwrapped to access the newly created instance.
Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching public constructor was found.
TypeLoadException typename was not found in assemblyName.
FileNotFoundException assemblyName was not found.
MethodAccessException The caller does not have permission to call this constructor.
Remarks
This method allows objects to be created remotely without having to load the type locally.

Use ObjectHandle.Unwrap to unwrap the return value.

.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   Type type,
   object[] args,
   object[] activationAttributes
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameters.
C# Syntax:
public static object CreateInstance(
   Type type,
   object[] args,
   object[] activationAttributes
);
Parameters:

type

The type of object to create.

args

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

activationAttributes

An array of one or more attributes that can participate in activation.

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible and provide the most specific match with the specified argument list.
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   Type type,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameters.
C# Syntax:
public static object CreateInstance(
   Type type,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture
);
Parameters:

type

The type of object to create.

bindingAttr

A combination of zero or more bit flags that affect the search for the type constructor. If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder

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

args

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

culture

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

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible and provide the most specific match with the specified argument list under the constraints of the specified binder and binding attributes.
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   Type type,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes
)
Summary
Creates an instance of the specified type using the constructor that best matches the specified parameters.
C# Syntax:
public static object CreateInstance(
   Type type,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes
);
Parameters:

type

The type of object to create.

bindingAttr

A combination of zero or more bit flags that affect the search for the type constructor. If bindingAttr is zero, a case-sensitive search for public constructors is conducted.

binder

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

args

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

culture

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

activationAttributes

An array of one or more attributes that can participate in activation.

Return Value:
A reference to the newly created object.
Exceptions
Exception Type Condition
ArgumentNullException type is null.
ArgumentException type is not a RuntimeType.
NotSupportedException type cannot be a TypeBuilder.
TargetInvocationException The constructor being called throws an exception.
MethodAccessException The caller does not have permission to call this constructor.
MissingMethodException No matching constructor was found.
Remarks
The constructor to be invoked must be accessible and provide the most specific match with the specified argument list under the constraints of the specified binder and binding attributes.
Example
            ObjectHandle            hdlSample;
            IMyExtenderInterface    myExtenderInterface;
            string                  argOne = "Value of argOne";
            int                     argTwo = 7;
            object[]                args = {argOne, argTwo};
            // Uses the UrlAttribute to create a remote object.
            object[]                activationAttributes = {new UrlAttribute("http://localhost:9000/MySampleService")};
            // Activates an object for this client.
            hdlSample = Activator.CreateInstance("SampleAssembly",
                                                 "samplenamespace.sampleclass", 
                                                 true,
                                                 BindingFlags.Instance|BindingFlags.Public,
                                                 null,
                                                 args,
                                                 null,
                                                 activationAttributes,
                                                 null);
            myExtenderInterface = (IMyExtenderInterface)hdlSample.Unwrap();
            Console.WriteLine(myExtenderInterface.SampleMethod("Bill"));

    
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstance(
   string assemblyName,
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes,
   Evidence securityInfo
)
Summary
Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the specified parameters.
C# Syntax:
public static ObjectHandle CreateInstance(
   string assemblyName,
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes,
   Evidence securityInfo
);
Parameters:

assemblyName

The name of the assembly where the type named typeName is sought. If assemblyName is null, the executing assembly is searched.

typeName

The name of the preferred type.

ignoreCase

A Boolean that specifies whether the search for typeName is case-sensitive. If ignoreCase is true, the search is not case-sensitive.

bindingAttr

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

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

args

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

culture

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

An array of one or more attributes that can participate in activation.

securityInfo

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

Return Value:
A handle that must be unwrapped to access the newly created instance.
Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching constructor was found.
TypeLoadException typename was not found in assemblyName.
FileNotFoundException assemblyName was not found.
MethodAccessException The caller does not have permission to call this constructor.
TargetInvocationException The constructor, which was invoked through reflection, threw an exception.
Remarks
This method allows objects to be created remotely without having to load the type locally.

Use ObjectHandle.Unwrap to unwrap the return value.

.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess

Return to top


Overloaded Method: CreateInstanceFrom(
   string assemblyFile,
   string typeName
)
Summary
Creates an instance of the type whose name is specified, using the named assembly file and default constructor.
C# Syntax:
public static ObjectHandle CreateInstanceFrom(
   string assemblyFile,
   string typeName
);
Parameters:

assemblyFile

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

typeName

The name of the preferred type.

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

-or-

null, if the requested type could not be created.

Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching public constructor was found.
TypeLoadException typename was not found in assemblyFile.
FileNotFoundException assemblyFile was not found.
MethodAccessException The caller does not have permission to call this constructor.
TargetInvocationException The constructor, which was invoked through reflection, threw an exception.
Remarks
This method allows objects to be created remotely without having to load the type locally.

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 Activator.CreateInstance methods.

.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess
.NET Framework Security:
FileIOPermission for the ability to search directory paths and read their contents. Associated enumerations: FileIOPermissionAccess/PathDiscovery and Read

Return to top


Overloaded Method: CreateInstanceFrom(
   string assemblyFile,
   string typeName,
   object[] activationAttributes
)
Summary
Creates an instance of the type whose name is specified, using the named assembly file and default constructor.
C# Syntax:
public static ObjectHandle CreateInstanceFrom(
   string assemblyFile,
   string typeName,
   object[] activationAttributes
);
Parameters:

assemblyFile

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

typeName

The name of the preferred type.

activationAttributes

An array of one or more attributes that can participate in activation.

Return Value:
A handle that must be unwrapped to access the newly created instance.
Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching public constructor was found.
TypeLoadException typename was not found in assemblyFile.
FileNotFoundException assemblyFile was not found.
MethodAccessException The caller does not have permission to call this constructor.
TargetInvocationException The constructor, which was invoked through reflection, threw an exception.
Remarks
This method allows objects to be created remotely without having to load the type locally.

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 Activator.CreateInstance methods.

Example
            ObjectHandle            hdlSample;
            IMyExtenderInterface    myExtenderInterface;
            object[]                activationAttributes = {new SynchronizationAttribute()};

            // Assumes that SampleAssembly.dll exists in the same directory as this assembly.
            hdlSample = Activator.CreateInstanceFrom("SampleAssembly.dll", "SampleNamespace.SampleClass", activationAttributes);
            // Assumes that the SampleClass implements an interface provided by
            // this application.
            myExtenderInterface = (IMyExtenderInterface)hdlSample.Unwrap();
            Console.WriteLine(myExtenderInterface.SampleMethod("Bill"));

    
.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess
.NET Framework Security:
FileIOPermission for the ability to search directory paths and read their contents. Associated enumerations: FileIOPermissionAccess/PathDiscovery and Read

Return to top


Overloaded Method: CreateInstanceFrom(
   string assemblyFile,
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes,
   Evidence securityInfo
)
Summary
Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters.
C# Syntax:
public static ObjectHandle CreateInstanceFrom(
   string assemblyFile,
   string typeName,
   bool ignoreCase,
   BindingFlags bindingAttr,
   Binder binder,
   object[] args,
   CultureInfo culture,
   object[] activationAttributes,
   Evidence securityInfo
);
Parameters:

assemblyFile

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

typeName

The name of the preferred type.

ignoreCase

A Boolean that specifies whether the search for typeName is case-sensitive. If ignoreCase is true, the search is not case-sensitive.

bindingAttr

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

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

args

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

culture

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

An array of one or more attributes that can participate in activation.

securityInfo

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

Return Value:
A handle that must be unwrapped to access the newly created instance.
Exceptions
Exception Type Condition
ArgumentNullException typeName is null.
MissingMethodException No matching constructor was found.
TypeLoadException typename was not found in assemblyFile.
FileNotFoundException assemblyFile was not found.
MethodAccessException The caller does not have permission to call this constructor.
TargetInvocationException The constructor, which was invoked through reflection, threw an exception.
Remarks
This method allows objects to be created remotely without having to load the type locally.

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 Activator.CreateInstance methods.

.NET Framework Security:
SecurityPermission for the ability to call unmanaged code when creating an instance of a delegate. Associated enumeration: SecurityPermissionFlag/UnmanagedCode
.NET Framework Security:
ReflectionPermission for the ability to invoke operations on all type members. Associated enumeration: ReflectionPermissionFlag/MemberAccess
.NET Framework Security:
FileIOPermission for the ability to search directory paths and read their contents. Associated enumerations: FileIOPermissionAccess/PathDiscovery and Read

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Activator();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: GetObject(
   Type type,
   string url
)
Summary
Creates a proxy for the well-known object indicated by the specified type and URL.
C# Syntax:
public static object GetObject(
   Type type,
   string url
);
Parameters:

type

The type of the well-known object to which you want to connect.

url

The URL of the well-known object.

Return Value:
A proxy that points to an endpoint served by the requested well-known object.
Exceptions
Exception Type Condition
ArgumentNullException type or url is null.
RemotingException type is not marshaled by reference or an interface.
Remarks
Call the proxy to send messages to the remote object. No messages are sent over the network until a method is called on the proxy.
See also:
WellKnownObjectMode | RemotingConfiguration

Return to top


Overloaded Method: GetObject(
   Type type,
   string url,
   object state
)
Summary
Creates a proxy for the well-known object indicated by the specified type, URL, and channel data.
C# Syntax:
public static object GetObject(
   Type type,
   string url,
   object state
);
Parameters:

type

The type of the well-known object to which you want to connect.

url

The URL of the well-known object.

state

Channel-specific data or null.

Return Value:
A proxy that points to an endpoint served by the requested well-known object.
Exceptions
Exception Type Condition
ArgumentNullException type or url is null.
RemotingException type is not marshaled by reference or an interface.
Remarks
Call the proxy to send messages to the remote object. No messages are sent over the network until a method is called on the proxy.

The state parameter communicates information to the channel, and is passed to the IChannelSender.CreateMessageSink method.

See also:
WellKnownObjectMode | RemotingConfiguration

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.