The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ErrorWrapper Class

Wraps objects the marshaler should marshal as a VT_ERROR.

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

public sealed class ErrorWrapper
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ErrorWrapper
public final class ErrorWrapper
Not applicable.

By default, Object type arguments are marshaled as a VARIANT type, where the object type determines the VARTYPE value of the VARIANT. For example, an integer type passed as Object is marshaled as a VT_I4. In order to marshal the integer as a variant of type VT_ERROR, the integer can be wrapped in the ErrorWrapper before making the method call.

Note that ErrorWrapper objects are not marshaled as type VT_ERROR after they are passed back from COM. Lone parameters are marshaled back from COM as type VT_I4, while arrays are marshaled back from COM as type VT_UI4.

For more information on VT_ERROR, please see the existing documentation for VARENUM::VT_ERROR in the MSDN library.

The following code example first demonstrates a lone Int32 object marshaled back from COM as an Int32 object. It then demonstrates an Int32 array marshaled back from COM as a UInt32 array.

// Scenario 1:
// Pass a lone parameter.
Int32 x = 3;
Object o = new ErrorWrapper(x);
// Pass 'o' to COM.
// On the return trip, 'o' has been unwrapped and is still an Int32 object.
Int32 y = (Int32)o;
Scenario 2:
// Pass an array parameter.
Int32[] arr = new Int32[3];
Object o = new ErrorWrapper(arr);
// Pass 'o' to COM.
// On the return trip, 'o' has been unwrapped and is now a UInt32[] array.
UInt32[ ] arr2 = (UInt32[])o;


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft