System.AppDomain.CreateInstanceAndUnwrap Method

Creates a new instance of the specified type. Parameters specify the assembly where the type is defined, and the name of the type.

Syntax

public object CreateInstanceAndUnwrap (string assemblyName, string typeName)

Parameters

assemblyName
The display name of the assembly. See System.Reflection.Assembly.FullName.
typeName
The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the Type.FullName property.

Returns

An instance of the object specified by typeName.

Remarks

This is a convenience method that combines AppDomain.CreateInstance(string, string) and System.Runtime.Remoting.ObjectHandle.Unwrap. This method calls the default constructor for typeName.

See System.Reflection.AssemblyName for the format of assemblyName. See the Type.FullName property for the format of typeName.

Note:

If you make an early-bound call to a method M of an object of type T1 that was returned by AppDomain.CreateInstanceAndUnwrap(string, string), and that method makes an early-bound call to a method of an object of type T2 in an assembly C other than the current assembly or the assembly containing T1, assembly C is loaded into the current application domain. This loading occurs even if the early-bound call to T1.M() was made in the body of a System.Reflection.Emit.DynamicMethod, or in other dynamically generated code. If the current domain is the default domain, assembly C cannot be unloaded until the process ends. If the current domain later attempts to load assembly C, the load might fail.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0