Export (0) Print
Expand All

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.

Overload List

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

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String) As ObjectHandle
[C#] public static ObjectHandle CreateInstanceFrom(string, string);
[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*);
[JScript] public static function CreateInstanceFrom(String, String) : ObjectHandle;

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

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String, Object()) As ObjectHandle
[C#] public static ObjectHandle CreateInstanceFrom(string, string, object[]);
[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*, Object[]);
[JScript] public static function CreateInstanceFrom(String, String, Object[]) : ObjectHandle;

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

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object(), CultureInfo, Object(), Evidence) As ObjectHandle
[C#] public static ObjectHandle CreateInstanceFrom(string, string, bool, BindingFlags, Binder, object[], CultureInfo, object[], Evidence);
[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*, bool, BindingFlags, Binder*, Object[], CultureInfo*, Object[], Evidence*);
[JScript] public static function CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) : ObjectHandle;

Example

[Visual Basic, C#, JScript] The following example demonstrates an overload of the CreateInstanceFrom method.

[Visual Basic, C#, JScript] Note   This example shows how to use one of the overloaded versions of CreateInstanceFrom. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim hdlSample As ObjectHandle
Dim myExtenderInterface As IMyExtenderInterface
Dim 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 = CType(hdlSample.Unwrap(), IMyExtenderInterface)
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"))

[C#] 
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"));

[JScript] 
var hdlSample : ObjectHandle;
var myExtenderInterface : IMyExtenderInterface;
var activationAttributes : Object[] = [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"));

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Activator Class | Activator Members | System Namespace

Show:
© 2014 Microsoft