System.Runtime.InteropServices Namespace
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
Classes
AllowReversePInvokeCallsAttribute |
Allows an unmanaged method to call a managed method. |
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. |
BStrWrapper |
Marshals data of type |
ClassInterfaceAttribute |
Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all. |
CoClassAttribute |
Specifies the class identifier of a coclass imported from a type library. |
CollectionsMarshal |
An unsafe class that provides a set of methods to access the underlying data representations of collections. |
ComAliasNameAttribute |
Indicates the COM alias for a parameter or field type. |
ComAwareEventInfo |
Permits late-bound registration of an event handler. |
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. |
ComEventsHelper |
Provides methods that enable .NET delegates that handle events to be added and removed from COM objects. |
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. |
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. |
ComWrappers |
Class for managing wrappers of COM IUnknown types. |
CriticalHandle |
Represents a wrapper class for handle resources. |
CurrencyWrapper |
Wraps objects the marshaler should marshal as a |
DefaultCharSetAttribute |
Specifies the value of the CharSet enumeration. This class cannot be inherited. |
DefaultDllImportSearchPathsAttribute |
Specifies the paths that are used to search for DLLs that provide functions for platform invokes. |
DefaultParameterValueAttribute |
Sets the default value of a parameter when called from a language that supports default parameters. This class cannot be inherited. |
DispatchWrapper |
Wraps objects the marshaler should marshal as a |
DispIdAttribute |
Specifies the COM dispatch identifier (DISPID) of a method, field, or property. |
DllImportAttribute |
Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point. |
DynamicInterfaceCastableImplementationAttribute |
Attribute required by any type that is returned by GetInterfaceImplementation(RuntimeTypeHandle). |
ErrorWrapper |
Wraps objects the marshaler should marshal as a |
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. |
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. |
IDispatchImplAttribute |
Indicates which |
ImmutableCollectionsMarshal |
An unsafe class that provides a set of methods to access the underlying data representations of immutable collections. |
ImportedFromTypeLibAttribute |
Indicates that the types defined within an assembly were originally defined in 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 |
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. |
JsonMarshal | |
LCIDConversionAttribute |
Indicates that a method's unmanaged signature expects a locale identifier (LCID) parameter. |
LibraryImportAttribute |
Indicates that a source generator should create a function for marshalling arguments instead of relying on the runtime to generate an equivalent marshalling function at run time. |
ManagedToNativeComInteropStubAttribute |
Provides support for user customization of interop stubs in managed-to-COM interop scenarios. |
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 MarshalAsAttribute it does not support. |
MemoryMarshal |
Provides methods to interoperate with Memory<T>, ReadOnlyMemory<T>, Span<T>, and ReadOnlySpan<T>. |
NativeLibrary |
Provides APIs for managing native libraries. |
NativeMemory |
This class contains methods that are mainly used to manage native memory. |
OptionalAttribute |
Indicates that a parameter is optional. |
OutAttribute |
Indicates that data should be marshaled from callee back to caller. |
PosixSignalContext |
Provides data for a PosixSignalRegistration event. |
PosixSignalRegistration |
Handles a PosixSignal. |
PreserveSigAttribute |
Indicates that the HRESULT 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. |
RegistrationServices |
Provides a set of services for registering and unregistering managed assemblies for use from COM. |
RuntimeEnvironment |
Provides a collection of |
RuntimeInformation |
Provides information about the .NET runtime installation. |
SafeArrayRankMismatchException |
The exception thrown when the rank of an incoming |
SafeArrayTypeMismatchException |
The exception thrown when the type of the incoming |
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. |
SequenceMarshal |
Provides a collection of methods for interoperating with ReadOnlySequence<T>. |
SetWin32ContextInIDispatchAttribute |
This attribute has been deprecated. |
StandardOleMarshalObject |
Replaces the standard common language runtime (CLR) free-threaded marshaler with the standard OLE STA marshaler. |
StructLayoutAttribute |
Lets you control the physical layout of the data fields of a class or structure in memory. |
SuppressGCTransitionAttribute |
Indicates that a garbage collection transition should be skipped when an unmanaged function call is made. |
TypeIdentifierAttribute |
Provides support for type equivalence. |
TypeLibConverter |
Provides a set of services that convert a managed assembly to a COM type library and vice versa. |
TypeLibFuncAttribute |
Contains the FUNCFLAGS that were originally imported for this method from the COM type library. |
TypeLibImportClassAttribute |
Specifies which Type exclusively uses an interface. This class cannot be inherited. |
TypeLibTypeAttribute |
Contains the TYPEFLAGS that were originally imported for this type from the COM type library. |
TypeLibVarAttribute |
Contains the VARFLAGS that were originally imported for this field from the COM type library. |
TypeLibVersionAttribute |
Specifies the version number of an exported type library. |
UnknownWrapper |
Wraps objects the marshaler should marshal as a |
UnmanagedCallConvAttribute |
Specifies the calling convention required to call P/Invoke methods implemented in unmanaged code. |
UnmanagedCallersOnlyAttribute |
Any method marked with UnmanagedCallersOnlyAttribute can be directly called from native code. The function token can be loaded to a local variable using the address-of operator in C# and passed as a callback to a native method. |
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. |
VariantWrapper |
Marshals data of type |
WasmImportLinkageAttribute |
Specifies that the P/Invoke marked with this attribute should be linked in as a WASM import. |
Structs
ArrayWithOffset |
Encapsulates an array and an offset within the specified array. |
BIND_OPTS |
Use BIND_OPTS instead. |
BINDPTR |
Use BINDPTR instead. |
CLong |
CLong is an immutable value type that represents the |
ComWrappers.ComInterfaceDispatch |
An application binary interface for function dispatch of a COM interface. |
ComWrappers.ComInterfaceEntry |
Interface type and pointer to targeted VTable. |
CONNECTDATA |
Use CONNECTDATA instead. |
CULong |
CULong is an immutable value type that represents the |
DISPPARAMS |
Use DISPPARAMS instead. |
ELEMDESC |
Use ELEMDESC instead. |
ELEMDESC.DESCUNION |
Use ELEMDESC.DESCUNION instead. |
EXCEPINFO |
Use EXCEPINFO instead. |
FILETIME |
Use FILETIME instead. |
FUNCDESC |
Use FUNCDESC instead. |
GCHandle |
Provides a way to access a managed object from unmanaged memory. |
HandleRef |
Wraps a managed object holding a handle to a resource that is passed to unmanaged code using platform invoke. |
IDLDESC |
Use IDLDESC instead. |
NFloat |
NFloat is an immutable value type that represents a floating type that has the same size as the native integer size.
It is meant to be used as an exchange type at the managed/unmanaged boundary to accurately represent in managed code unmanaged APIs that use a type alias for C or C++'s |
OSPlatform |
Represents an operating system platform. |
PARAMDESC |
Use PARAMDESC instead. |
STATSTG |
Use STATSTG instead. |
TYPEATTR |
Use TYPEATTR instead. |
TYPEDESC |
Use TYPEDESC instead. |
TYPELIBATTR |
Use TYPELIBATTR instead. |
VARDESC |
Use VARDESC instead. |
VARDESC.DESCUNION |
Use VARDESC.DESCUNION instead. |
Interfaces
_Activator |
Exposes the Activator class to unmanaged code. |
_Assembly |
Exposes the public members of the Assembly class to unmanaged code. |
_AssemblyBuilder |
Exposes the AssemblyBuilder class to unmanaged code. |
_AssemblyName |
Exposes the AssemblyName class to unmanaged code. |
_Attribute |
Exposes the Attribute class to unmanaged code. |
_ConstructorBuilder |
Exposes the ConstructorBuilder class to unmanaged code. |
_ConstructorInfo |
Exposes the public members of the ConstructorInfo class to unmanaged code. |
_CustomAttributeBuilder |
Exposes the CustomAttributeBuilder class to unmanaged code. |
_EnumBuilder |
Exposes the EnumBuilder class to unmanaged code. |
_EventBuilder |
Exposes the EventBuilder class to unmanaged code. |
_EventInfo |
Exposes the public members of the EventInfo class to unmanaged code. |
_Exception |
Exposes the public members of the Exception class to unmanaged code. |
_FieldBuilder |
Exposes the FieldBuilder class to unmanaged code. |
_FieldInfo |
Exposes the public members of the FieldInfo class to unmanaged code. |
_ILGenerator |
Exposes the ILGenerator class to unmanaged code. |
_LocalBuilder |
Exposes the LocalBuilder class to unmanaged code. |
_MemberInfo |
Exposes the public members of the MemberInfo class to unmanaged code. |
_MethodBase |
Exposes the public members of the MethodBase class to unmanaged code. |
_MethodBuilder |
Exposes the MethodBuilder class to unmanaged code. |
_MethodInfo |
Exposes the public members of the MethodInfo class to unmanaged code. |
_MethodRental |
Exposes the MethodRental class to unmanaged code. |
_Module |
Exposes the Module class to unmanaged code. |
_ModuleBuilder |
Exposes the ModuleBuilder class to unmanaged code. |
_ParameterBuilder |
Exposes the ParameterBuilder class to unmanaged code. |
_ParameterInfo |
Exposes the ParameterInfo class to unmanaged code. |
_PropertyBuilder |
Exposes the PropertyBuilder class to unmanaged code. |
_PropertyInfo |
Exposes the public members of the PropertyInfo class to unmanaged code. |
_SignatureHelper |
Exposes the SignatureHelper class to unmanaged code. |
_Thread |
Exposes the Thread class to unmanaged code. |
_Type |
Exposes the public members of the Type class to the unmanaged code. |
_TypeBuilder |
Exposes the TypeBuilder class to unmanaged code. |
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. |
ICustomQueryInterface |
Enables developers to provide a custom, managed implementation of the IUnknown::QueryInterface(REFIID riid, void **ppvObject) method. |
IDynamicInterfaceCastable |
Interface used to participate in a type cast failure. |
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. |
UCOMIBindCtx |
Use BIND_OPTS instead. |
UCOMIConnectionPoint |
Use IConnectionPoint instead. |
UCOMIConnectionPointContainer |
Use IConnectionPointContainer instead. |
UCOMIEnumConnectionPoints |
Use IEnumConnectionPoints instead. |
UCOMIEnumConnections |
Use IEnumConnections instead. |
UCOMIEnumMoniker |
Use IEnumMoniker instead. |
UCOMIEnumString |
Use IEnumString instead. |
UCOMIEnumVARIANT |
Use IEnumVARIANT instead. |
UCOMIMoniker |
Use IMoniker instead. |
UCOMIPersistFile |
Use IPersistFile instead. |
UCOMIRunningObjectTable |
Use IRunningObjectTable instead. |
UCOMIStream |
Use IStream instead. |
UCOMITypeComp |
Use ITypeComp instead. |
UCOMITypeInfo |
Use ITypeInfo instead. |
UCOMITypeLib |
Use ITypeLib instead. |
Enums
Architecture |
Indicates the processor architecture. |
AssemblyRegistrationFlags |
Defines a set of flags used when registering assemblies. |
CALLCONV |
Use CALLCONV instead. |
CallingConvention |
Specifies the calling convention required to call methods implemented in unmanaged code. |
CharSet |
Dictates which character set marshaled strings should use. |
ClassInterfaceType |
Identifies the type of class interface that is generated for a class. |
ComInterfaceType |
Identifies how to expose an interface to COM. |
ComMemberType |
Describes the type of a COM member. |
CreateComInterfaceFlags |
Specifies flags for the GetOrCreateComInterfaceForObject(Object, CreateComInterfaceFlags) method. |
CreateObjectFlags |
Specifies flags for the GetOrCreateObjectForComInstance(IntPtr, CreateObjectFlags) method. |
CustomQueryInterfaceMode |
Indicates whether the GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) method's IUnknown::QueryInterface calls can use the ICustomQueryInterface interface. |
CustomQueryInterfaceResult |
Provides return values for the GetInterface(Guid, IntPtr) method. |
DESCKIND |
Use DESCKIND instead. |
DllImportSearchPath |
Specifies the paths that are used to search for DLLs that provide functions for platform invokes. |
ExporterEventKind |
Describes the callbacks that the type library exporter makes when exporting a type library. |
FUNCFLAGS |
Use FUNCFLAGS instead. |
FUNCKIND |
Use FUNCKIND instead. |
GCHandleType |
Represents the types of handles the GCHandle type can allocate. |
IDispatchImplType |
Indicates which |
IDLFLAG |
Use IDLFLAG instead. |
IMPLTYPEFLAGS |
Use IMPLTYPEFLAGS instead. |
ImporterEventKind |
Describes the callbacks that the type library importer makes when importing a type library. |
INVOKEKIND |
Use INVOKEKIND instead. |
LayoutKind |
Controls the layout of an object when exported to unmanaged code. |
LIBFLAGS |
Use LIBFLAGS instead. |
PARAMFLAG |
Use PARAMFLAG instead. |
PosixSignal |
Specifies a POSIX signal number. |
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. |
StringMarshalling |
Specifies how strings should be marshalled for generated p/invokes |
SYSKIND |
Use SYSKIND instead. |
TYPEFLAGS |
Use TYPEFLAGS instead. |
TYPEKIND |
Use TYPEKIND instead. |
TypeLibExporterFlags |
Indicates how a type library should be produced. |
TypeLibFuncFlags |
Describes the original settings of the |
TypeLibImporterFlags |
Indicates how an assembly should be produced. |
TypeLibTypeFlags |
Describes the original settings of the TYPEFLAGS in the COM type library from which the type was imported. |
TypeLibVarFlags |
Describes the original settings of the VARFLAGS in the COM type library from which the variable was imported. |
UnmanagedType |
Identifies how to marshal parameters or fields to unmanaged code. |
VarEnum |
Indicates how to marshal the array elements when an array is marshaled from managed to unmanaged code as a SafeArray. |
VARFLAGS |
Use VARFLAGS instead. |
Delegates
DllImportResolver |
Provides a delegate used to resolve native libraries via callback. |
ObjectCreationDelegate |
Creates a COM object. |
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 DllImportAttribute, which you use to define platform invoke methods for accessing unmanaged APIs, and MarshalAsAttribute, which you use to specify how data is marshaled between managed and unmanaged memory.