Compartir a través de


Custom Marshaling Overview 

The marshaler essentially provides a bridge between the functionality of old and new interfaces. Custom marshaling enables clients that you designed to work with an old interface to also work with servers that only implement a new interface. Custom marshaling also enables clients built to work with a new interface to work with servers that expose the old interface.

Instead of using the interop marshaler, you can design a custom marshaler for an interface that introduces different marshaling behavior or exposes the interface to COM in a different way. By using a custom marshaler, you can minimize the distinction between new .NET components and existing COM components.

For example, suppose that you are developing a managed interface called INew. When exposed to COM through a standard COM callable wrapper, the interface has the same methods as the managed interface and uses the marshaling rules built into the interop marshaler. Further suppose that a well-known COM interface called IOld already provides the same functionality as the INew interface. By introducing a custom marshaler, you can provide an unmanaged implementation of IOld that simply delegates the calls to the managed implementation of the INew interface. The custom marshaler essentially acts as a bridge between the managed and unmanaged interfaces.

Note that custom marshalers are not invoked when calling from the managed side to unmanaged side on a dispatch only interface.

See Also

Concepts

Defining the Marshaling Type
Implementing the ICustomMarshaler Interface
Using a Substitute Marshaler