Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Tools
Development Tools
FxCop
FxCop Warnings
 Do not use AutoDual ClassInterfaceT...

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

Other versions are also available for the following:
Visual Studio Team System
Do not use AutoDual ClassInterfaceType

TypeName

DoNotUseAutoDualClassInterfaceType

CheckId

CA1408

Category

Microsoft.Interoperability

Breaking Change

Breaking

Types that use a dual interface allow clients to bind to a specific interface layout. Any changes in a future version to the layout of the type or any base types will break COM clients that bind to the interface. By default, if the ClassInterfaceAttribute attribute is not specified, a dispatch-only interface is used.

Unless marked otherwise, all public non-generic types are visible to COM; all non-public and generic types are invisible to COM.

To fix a violation of this rule change the value of the ClassInterfaceAttribute attribute to None and explicitly define the interface.

Do not exclude a warning from this rule unless it is certain that the layout of the type and its base types will not change in a future version.

The following example shows a class that violates the rule and a re-declaration of the class to use an explicit interface.

Visual Basic
Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(True)>
Namespace InteroperabilityLibrary

   ' This violates the rule.
   <ClassInterfaceAttribute(ClassInterfaceType.AutoDual)> _ 
   Public Class DualInterface
      Public Sub SomeSub
      End Sub
   End Class

   Public Interface IExplicitInterface
      Sub SomeSub
   End Interface

   <ClassInterfaceAttribute(ClassInterfaceType.None)> _ 
   Public Class ExplicitInterface
      Implements IExplicitInterface

      Public Sub SomeSub Implements IExplicitInterface.SomeSub
      End Sub

   End Class

End Namespace
C#
using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(true)]
namespace InteroperabilityLibrary
{
   // This violates the rule.
   [ClassInterface(ClassInterfaceType.AutoDual)]
   public class DualInterface
   {
      public void SomeMethod() {}
   }

   public interface IExplicitInterface
   {
      void SomeMethod();
   }

   [ClassInterface(ClassInterfaceType.None)]
   public class ExplicitInterface : IExplicitInterface
   {
      public void SomeMethod() {}
   }
}
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