This documentation is archived and is not being maintained.

ICustomMarshaler Interface

Designed to provide custom wrappers for handling method calls.

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

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0