System.Runtime.InteropServices Namespace

The System.Runtime.InteropServices namespace provides a wide variety of members that support COM interop and platform invoke services. If you are unfamiliar with these services, see Interoperating with Unmanaged Code.

Remarks

Members of this namespace provide several categories of functionality, as shown in the following table. Attributes control marshaling behavior, such as how to arrange structures or how to represent strings. The most important attributes are System.Runtime.InteropServices.DllImportAttribute, which you use to define platform invoke methods for accessing unmanaged APIs, and System.Runtime.InteropServices.MarshalAsAttribute, which you use to specify how data is marshaled between managed and unmanaged memory.

Classes

TypeReason
_Activator

Exposes the Activator class to unmanaged code.

_Assembly

Exposes the public members of the System.Reflection.Assembly class to unmanaged code.

_AssemblyBuilder

Exposes the System.Reflection.Emit.AssemblyBuilder class to unmanaged code.

_AssemblyName

Exposes the System.Reflection.AssemblyName class to unmanaged code.

_Attribute

Exposes the Attribute class to unmanaged code.

_ConstructorBuilder

Exposes the System.Reflection.Emit.ConstructorBuilder class to unmanaged code.

_ConstructorInfo

Exposes the public members of the System.Reflection.ConstructorInfo class to unmanaged code.

_CustomAttributeBuilder

Exposes the System.Reflection.Emit.CustomAttributeBuilder class to unmanaged code.

_EnumBuilder

Exposes the System.Reflection.Emit.EnumBuilder class to unmanaged code.

_EventBuilder

Exposes the System.Reflection.Emit.EventBuilder class to unmanaged code.

_EventInfo

Exposes the public members of the System.Reflection.EventInfo class to unmanaged code.

_Exception

Exposes the public members of the Exception class to unmanaged code.

_FieldBuilder

Exposes the System.Reflection.Emit.FieldBuilder class to unmanaged code.

_FieldInfo

Exposes the public members of the System.Reflection.FieldInfo class to unmanaged code.

_ILGenerator

Exposes the System.Reflection.Emit.ILGenerator class to unmanaged code.

_LocalBuilder

Exposes the System.Reflection.Emit.LocalBuilder class to unmanaged code.

_MemberInfo

Exposes the public members of the System.Reflection.MemberInfo class to unmanaged code.

_MethodBase

Exposes the public members of the System.Reflection.MethodBase class to unmanaged code.

_MethodBuilder

Exposes the System.Reflection.Emit.MethodBuilder class to unmanaged code.

_MethodInfo

Exposes the public members of the System.Reflection.MethodInfo class to unmanaged code.

_MethodRental

Exposes the System.Reflection.Emit.MethodRental class to unmanaged code.

_Module

Exposes the System.Reflection.Module class to unmanaged code.

_ModuleBuilder

Exposes the System.Reflection.Emit.ModuleBuilder class to unmanaged code.

_ParameterBuilder

Exposes the System.Reflection.Emit.ParameterBuilder class to unmanaged code.

_ParameterInfo

Exposes the System.Reflection.ParameterInfo class to unmanaged code.

_PropertyBuilder

Exposes the System.Reflection.Emit.PropertyBuilder class to unmanaged code.

_PropertyInfo

Exposes the public members of the System.Reflection.PropertyInfo class to unmanaged code.

_SignatureHelper

Exposes the System.Reflection.Emit.SignatureHelper class to unmanaged code.

_Thread

Exposes the System.Threading.Thread class to unmanaged code.

_Type

Exposes the public members of the Type class to the unmanaged code.

_TypeBuilder

Exposes the System.Reflection.Emit.TypeBuilder class to unmanaged code.

AllowReversePInvokeCallsAttribute

Allows an unmanaged method to call a managed method.

ArrayWithOffset

Encapsulates an array and an offset within the specified array.

AssemblyRegistrationFlags

Defines a set of flags used when registering assemblies.

AutomationProxyAttribute

Specifies whether the type should be marshaled using the Automation marshaler or a custom proxy and stub.

BestFitMappingAttribute

Controls whether Unicode characters are converted to the closest matching ANSI characters.

BIND_OPTS

Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.

BINDPTR

Use System.Runtime.InteropServices.ComTypes.BINDPTR instead.

BStrWrapper

Marshals data of type VT_BSTR from managed to unmanaged code. This class cannot be inherited.

CALLCONV

Use System.Runtime.InteropServices.ComTypes.CALLCONV instead.

CallingConvention

Specifies the calling convention required to call methods implemented in unmanaged code.

CharSet

Dictates which character set marshaled strings should use.

ClassInterfaceAttribute

Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all.

ClassInterfaceType

Identifies the type of class interface that is generated for a class.

CoClassAttribute

Specifies the class identifier of a coclass imported from a type library.

ComAliasNameAttribute

Indicates the COM alias for a parameter or field type.

ComCompatibleVersionAttribute

Indicates to a COM client that all classes in the current version of an assembly are compatible with classes in an earlier version of the assembly.

ComConversionLossAttribute

Indicates that information was lost about a class or interface when it was imported from a type library to an assembly.

ComDefaultInterfaceAttribute

Specifies a default interface to expose to COM. This class cannot be inherited.

ComEventInterfaceAttribute

Identifies the source interface and the class that implements the methods of the event interface that is generated when a coclass is imported from a COM type library.

COMException

The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.

ComImportAttribute

Indicates that the attributed type was previously defined in COM.

ComInterfaceType

Identifies how to expose an interface to COM.

ComMemberType

Describes the type of a COM member.

ComRegisterFunctionAttribute

Specifies the method to call when you register an assembly for use from COM; this enables the execution of user-written code during the registration process.

ComSourceInterfacesAttribute

Identifies a list of interfaces that are exposed as COM event sources for the attributed class.

ComUnregisterFunctionAttribute

Specifies the method to call when you unregister an assembly for use from COM; this allows for the execution of user-written code during the unregistration process.

ComVisibleAttribute

Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.

CONNECTDATA

Use System.Runtime.InteropServices.ComTypes.CONNECTDATA instead.

CriticalHandle

Represents a wrapper class for handle resources.

CurrencyWrapper

Wraps objects the marshaler should marshal as a VT_CY.

DefaultCharSetAttribute

Specifies the value of the System.Runtime.InteropServices.CharSet enumeration. This class cannot be inherited.

DefaultParameterValueAttribute

Sets the default value of a parameter when called from a language that supports default parameters. This class cannot be inherited.

DESCKIND

Use System.Runtime.InteropServices.ComTypes.DESCKIND instead.

DispatchWrapper

Wraps objects the marshaler should marshal as a VT_DISPATCH.

DispIdAttribute

Specifies the COM dispatch identifier (DISPID) of a method, field, or property.

DISPPARAMS

Use System.Runtime.InteropServices.ComTypes.DISPPARAMS instead.

DllImportAttribute

Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.

ELEMDESC

Use System.Runtime.InteropServices.ComTypes.ELEMDESC instead.

ELEMDESC+DESCUNIONDocumentation for this section has not yet been entered.
ErrorWrapper

Wraps objects the marshaler should marshal as a VT_ERROR.

EXCEPINFO

Use System.Runtime.InteropServices.ComTypes.EXCEPINFO instead.

ExporterEventKind

Describes the callbacks that the type library exporter makes when exporting a type library.

ExtensibleClassFactory

Enables customization of managed objects that extend from unmanaged objects during creation.

ExternalException

The base exception type for all COM interop exceptions and structured exception handling (SEH) exceptions.

FieldOffsetAttribute

Indicates the physical position of fields within the unmanaged representation of a class or structure.

FILETIME

Use System.Runtime.InteropServices.ComTypes.FILETIME instead.

FUNCDESC

Use System.Runtime.InteropServices.ComTypes.FUNCDESC instead.

FUNCFLAGS

Use System.Runtime.InteropServices.ComTypes.FUNCFLAGS instead.

FUNCKIND

Use System.Runtime.InteropServices.ComTypes.FUNCKIND instead.

GCHandle

Provides a way to access a managed object from unmanaged memory.

GCHandleType

Represents the types of handles the System.Runtime.InteropServices.GCHandle class can allocate.

GuidAttribute

Supplies an explicit Guid when an automatic GUID is undesirable.

HandleCollector

Tracks outstanding handles and forces a garbage collection when the specified threshold is reached.

HandleRef

Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke.

ICustomAdapter

Provides a way for clients to access the actual object, rather than the adapter object handed out by a custom marshaler.

ICustomFactory

Enables users to write activation code for managed objects that extend MarshalByRefObject.

ICustomMarshaler

Provides custom wrappers for handling method calls.

IDispatchImplAttribute

Indicates which IDispatch implementation the common language runtime uses when exposing dual interfaces and dispinterfaces to COM.

IDispatchImplType

Indicates which IDispatch implementation to use for a particular class.

IDLDESC

Use System.Runtime.InteropServices.ComTypes.IDLDESC instead.

IDLFLAG

Use System.Runtime.InteropServices.ComTypes.IDLFLAG instead.

IMPLTYPEFLAGS

Use System.Runtime.InteropServices.ComTypes.IMPLTYPEFLAGS instead.

ImportedFromTypeLibAttribute

Indicates that the types defined within an assembly were originally defined in a type library.

ImporterEventKind

Describes the callbacks that the type library importer makes when importing a type library.

InAttribute

Indicates that data should be marshaled from the caller to the callee, but not back to the caller.

InterfaceTypeAttribute

Indicates whether a managed interface is dual, dispatch-only, or IUnknown -only when exposed to COM.

InvalidComObjectException

The exception thrown when an invalid COM object is used.

InvalidOleVariantTypeException

The exception thrown by the marshaler when it encounters an argument of a variant type that can not be marshaled to managed code.

INVOKEKIND

Use System.Runtime.InteropServices.ComTypes.INVOKEKIND instead.

IRegistrationServices

Provides a set of services for registering and unregistering managed assemblies for use from COM.

ITypeLibConverter

Provides a set of services that convert a managed assembly to a COM type library and vice versa.

ITypeLibExporterNameProvider

Provides control over the casing of names when exported to a type library.

ITypeLibExporterNotifySink

Provides a callback mechanism for the assembly converter to inform the caller of the status of the conversion, and involve the caller in the conversion process itself.

ITypeLibImporterNotifySink

Provides a callback mechanism for the type library converter to inform the caller of the status of the conversion, and involve the caller in the conversion process itself.

LayoutKind

Controls the layout of an object when exported to unmanaged code.

LCIDConversionAttribute

Indicates that a method's unmanaged signature expects a locale identifier (LCID) parameter.

LIBFLAGS

Use System.Runtime.InteropServices.ComTypes.LIBFLAGS instead.

Marshal

Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code.

MarshalAsAttribute

Indicates how to marshal the data between managed and unmanaged code.

MarshalDirectiveException

The exception that is thrown by the marshaler when it encounters a System.Runtime.InteropServices.MarshalAsAttribute it does not support.

ObjectCreationDelegate

Creates a COM object.

OptionalAttribute

Indicates that a parameter is optional.

OutAttribute

Indicates that data should be marshaled from callee back to caller.

PARAMDESC

Use System.Runtime.InteropServices.ComTypes.PARAMDESC instead.

PARAMFLAG

Use System.Runtime.InteropServices.ComTypes.PARAMFLAG instead.

PreserveSigAttribute

Indicates that the HRESULT or retval signature transformation that takes place during COM interop calls should be suppressed.

PrimaryInteropAssemblyAttribute

Indicates that the attributed assembly is a primary interop assembly.

ProgIdAttribute

Allows the user to specify the ProgID of a class.

RegistrationClassContext

Specifies the set of execution contexts in which a class object will be made available for requests to construct instances.

RegistrationConnectionType

Defines the types of connections to a class object.

RegistrationServices

Provides a set of services for registering and unregistering managed assemblies for use from COM.

RuntimeEnvironment

Provides a collection of static methods that return information about the common language runtime environment.

SafeArrayRankMismatchException

The exception thrown when the rank of an incoming SAFEARRAY does not match the rank specified in the managed signature.

SafeArrayTypeMismatchException

The exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature.

SafeBuffer

Provides a controlled memory buffer that can be used for reading and writing. Attempts to access memory outside the controlled buffer (underruns and overruns) raise exceptions.

SafeHandle

Represents a wrapper class for operating system handles. This class must be inherited.

SEHException

Represents structured exception handling (SEH) errors.

SetWin32ContextInIDispatchAttribute

This attribute has been deprecated.

StandardOleMarshalObject

Replaces the standard common language runtime (CLR) free-threaded marshaler with the standard OLE STA marshaler.

STATSTG

Use System.Runtime.InteropServices.ComTypes.STATSTG instead.

StructLayoutAttribute

Lets you control the physical layout of the data fields of a class or structure.

SYSKIND

Use System.Runtime.InteropServices.ComTypes.SYSKIND instead.

TYPEATTR

Use System.Runtime.InteropServices.ComTypes.TYPEATTR instead.

TYPEDESC

Use System.Runtime.InteropServices.ComTypes.TYPEDESC instead.

TYPEFLAGS

Use System.Runtime.InteropServices.ComTypes.TYPEFLAGS instead.

TypeIdentifierAttribute

Provides support for type equivalence.

TYPEKIND

Use System.Runtime.InteropServices.ComTypes.TYPEKIND instead.

TYPELIBATTR

Use System.Runtime.InteropServices.ComTypes.TYPELIBATTR instead.

TypeLibConverter

Provides a set of services that convert a managed assembly to a COM type library and vice versa.

TypeLibExporterFlags

Indicates how a type library should be produced.

TypeLibFuncAttribute

Contains the System.Runtime.InteropServices.FUNCFLAGS that were originally imported for this method from the COM type library.

TypeLibFuncFlags

Describes the original settings of the FUNCFLAGS in the COM type library from where this method was imported.

TypeLibImportClassAttribute

Specifies which Type exclusively uses an interface. This class cannot be inherited.

TypeLibImporterFlags

Indicates how an assembly should be produced.

TypeLibTypeAttribute

Contains the System.Runtime.InteropServices.TYPEFLAGS that were originally imported for this type from the COM type library.

TypeLibTypeFlags

Describes the original settings of the System.Runtime.InteropServices.TYPEFLAGS in the COM type library from which the type was imported.

TypeLibVarAttribute

Contains the System.Runtime.InteropServices.VARFLAGS that were originally imported for this field from the COM type library.

TypeLibVarFlags

Describes the original settings of the System.Runtime.InteropServices.VARFLAGS in the COM type library from which the variable was imported.

TypeLibVersionAttribute

Specifies the version number of an exported type library.

UCOMIBindCtx

Use System.Runtime.InteropServices.ComTypes.BIND_OPTS instead.

UCOMIConnectionPoint

Use System.Runtime.InteropServices.ComTypes.IConnectionPoint instead.

UCOMIConnectionPointContainer

Use System.Runtime.InteropServices.ComTypes.IConnectionPointContainer instead.

UCOMIEnumConnectionPoints

Use System.Runtime.InteropServices.ComTypes.IEnumConnectionPoints instead.

UCOMIEnumConnections

Use System.Runtime.InteropServices.ComTypes.IEnumConnections instead.

UCOMIEnumMoniker

Use System.Runtime.InteropServices.ComTypes.IEnumMoniker instead.

UCOMIEnumString

Use System.Runtime.InteropServices.ComTypes.IEnumString instead.

UCOMIEnumVARIANT

Use System.Runtime.InteropServices.ComTypes.IEnumVARIANT instead.

UCOMIMoniker

Use System.Runtime.InteropServices.ComTypes.IMoniker instead.

UCOMIPersistFile

Use System.Runtime.InteropServices.ComTypes.IPersistFile instead.

UCOMIRunningObjectTable

Use System.Runtime.InteropServices.ComTypes.IRunningObjectTable instead.

UCOMIStream

Use System.Runtime.InteropServices.ComTypes.IStream instead.

UCOMITypeComp

Use System.Runtime.InteropServices.ComTypes.ITypeComp instead.

UCOMITypeInfo

Use System.Runtime.InteropServices.ComTypes.ITypeInfo instead.

UCOMITypeLib

Use System.Runtime.InteropServices.ComTypes.ITypeLib instead.

UnknownWrapper

Wraps objects the marshaler should marshal as a VT_UNKNOWN.

UnmanagedFunctionPointerAttribute

Controls the marshaling behavior of a delegate signature passed as an unmanaged function pointer to or from unmanaged code. This class cannot be inherited.

UnmanagedType

Identifies how to marshal parameters or fields to unmanaged code.

VARDESC

Use System.Runtime.InteropServices.ComTypes.VARDESC instead.

VARDESC+DESCUNIONDocumentation for this section has not yet been entered.
VarEnum

Indicates how to marshal the array elements when an array is marshaled from managed to unmanaged code as a System.Runtime.InteropServices.UnmanagedType.SafeArray.

VARFLAGS

Use System.Runtime.InteropServices.ComTypes.VARFLAGS instead.

VariantWrapper

Marshals data of type VT_VARIANT | VT_BYREF from managed to unmanaged code. This class cannot be inherited.