Share via


CreateInstanceAndUnwrap Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function CreateInstanceAndUnwrap ( _
    assemblyName As String, _
    typeName As String _
) As Object
public Object CreateInstanceAndUnwrap(
    string assemblyName,
    string typeName
)
public:
Object^ CreateInstanceAndUnwrap(
    String^ assemblyName, 
    String^ typeName
)
member CreateInstanceAndUnwrap : 
        assemblyName:string * 
        typeName:string -> Object 
public function CreateInstanceAndUnwrap(
    assemblyName : String, 
    typeName : String
) : Object

Parameters

Return Value

Type: System. . :: . .Object
An instance of the object specified by typeName.

Exceptions

Exception Condition
ArgumentNullException

assemblyName or typeName is null Nothing nullptr unit a null reference (Nothing in Visual Basic) .

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.

AppDomainUnloadedException

The operation is attempted on an unloaded application ___domain.

BadImageFormatException

assemblyName is not a valid assembly.

-or-

Version 2.0 or later of the common language runtime is currently loaded and assemblyName was compiled with a later version.

FileLoadException

An assembly or module was loaded twice with two different evidences.

Remarks

This is a convenience method that combines CreateInstance and ObjectHandle.Unwrap. This method calls the default constructor for typeName.

See 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 CreateInstanceAndUnwrap, 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 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.

.NET Framework Security

See Also

Reference

AppDomain Class

System Namespace