Name

PreserveSigAttribute

Synopsis

When .NET converts a managed method signature to an unmanaged signature, it changes the return value to a parameter that has the out and retval COM attributes. Instead of the original return value, the unmanaged method returns a COM HRESULT. If you want to override this behavior, attach the PreserveSigAttribute to the method.

Something similar happens when you call unmanaged methods from managed code. In that case, the [out, retval] parameter on the COM side becomes the return value, and an HRESULT that indicates an error condition is translated into a .NET exception. If you want to be able to access the HRESULT as a long return value, use the PreserveSigAttribute on the methods in your COM interface declaration (see InterfaceTypeAttribute).

public sealed class PreserveSigAttribute : Attribute {
// Public Constructors
   public method PreserveSigAttribute();  
}

Hierarchy

System.ObjectSystem.AttributePreserveSigAttribute

Valid On

Method

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.