Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
InterfaceTypeAttribute Class

Indicates whether a managed interface is dual, dispatch-only, or IUnknown -only when exposed to COM.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Interface, Inherited := False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class InterfaceTypeAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As InterfaceTypeAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Interface, Inherited = false)]
[ComVisibleAttribute(true)]
public sealed class InterfaceTypeAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Interface, Inherited = false)]
[ComVisibleAttribute(true)]
public ref class InterfaceTypeAttribute sealed : public Attribute
JScript
public final class InterfaceTypeAttribute extends Attribute

You can apply this attribute to interfaces.

By default, the Type Library Exporter (Tlbexp.exe) exposes a managed interface to COM as a dual interface, giving you the flexibility of late binding or the performance of early binding. The ComInterfaceType enumeration enables you to override the default behavior and specify late binding only or early binding only. For example, you can apply InterfaceType (ComInterfaceType.InterfaceIsIDispatch) to an interface to produce metadata to restrict callers to late binding only. Although interfaces that derive from the IDispatch interface are often dual, the InterfaceIsIDispatch enumeration member allows only late-bound calls to the interface methods. This attribute has no effect on the managed view of the interface. For additional information on how interfaces are exposed to COM, see Exported Type Conversion.

The Type Library Importer (Tlbimp.exe) also applies this attribute to imported, nondual interfaces; it applies the appropriate enumeration member to indicate that the interface is dispatch-only or IUnknown -only.

The following example shows how InterfaceTypeAttribute controls how the interface is exposed to COM.

Visual Basic
Imports System.Runtime.InteropServices

'Interface is exposed to COM as dual.
Interface IMyInterface1
     'Insert code here.
End Interface

'Interface is exposed to COM as IDispatch.
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)> _
Interface IMyInterface2
    'Insert code here.
End Interface

C#
using System.Runtime.InteropServices;

//Interface is exposed to COM as dual.
interface IMyInterface1 
{
    //Insert code here.
}

//Interface is exposed to COM as IDispatch.
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
interface IMyInterface2 
{
    //Insert code here.
}

Visual C++
using namespace System::Runtime::InteropServices;

//Interface is exposed to COM as dual.
interface class IMyInterface1{};

//Insert code here.
//Interface is exposed to COM as IDispatch.

[InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIDispatch)]
interface class IMyInterface2{};
//Insert code here.

JScript
import System.Runtime.InteropServices

//Interface will be exposed to COM as dual.
interface IMyInterface1{
     // ...
}

//Interface will be exposed to COM as IDispatch.
public InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)
interface IMyInterface2{
    // ...
}

System..::.Object
  System..::.Attribute
    System.Runtime.InteropServices..::.InterfaceTypeAttribute
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 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, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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

.NET Compact Framework

Supported in: 3.5, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker