ICustomMarshaler Interface

Designed to provide custom wrappers for handling method calls.

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

public interface ICustomMarshaler
/** @attribute ComVisibleAttribute(true) */ 
public interface ICustomMarshaler
public interface ICustomMarshaler

To use a custom marshaler, you must apply the MarshalAsAttribute to the parameter or field being marshaled. You must also pass UnmanagedType.CustomMarshaler to its constructor and specify the MarshalType. The attribute identifies the appropriate custom marshaler to activate the appropriate wrapper. The common language runtime's interop service then examines the attribute and creates the custom marshaler when the argument is marshaled. It calls on the custom marshaler's MarshalNativeToManaged and MarshalManagedToNative methods to activate the correct wrapper to handle the call.

In addition to implementing the ICustomMarshaler interface, custom marshalers must implement a static method called GetInstance that accepts a String as a parameter and has a return type of ICustomMarshaler. This static method is called by the common language runtime's COM interop layer to instantiate an instance of the custom marshaler. The String passed to GetInstance is a cookie that the method can use to customize the returned custom marshaler.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0