Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Avoid overloads in COM visible interfaces

Avoid overloads in ComVisible interfaces







Breaking Change


A COM visible interface declares overloaded methods.

When overloaded methods are exposed to COM clients, only the first method overload retains its name. Subsequent overloads are uniquely renamed by appending to the name an underscore character '_' and an integer that corresponds to the order of declaration of the overload. For example, consider the following methods:

   void SomeMethod(int valueOne);
   void SomeMethod(int valueOne, int valueTwo, int valueThree);
   void SomeMethod(int valueOne, int valueTwo);

These methods are exposed to COM clients as:

   void SomeMethod(int valueOne);
   void SomeMethod_2(int valueOne, int valueTwo, int valueThree);
   void SomeMethod_3(int valueOne, int valueTwo);

Visual Basic 6 COM clients cannot implement interface methods with an underscore in the name.

To fix a violation of this rule rename the overloaded methods so that the names are unique. Alternatively, make the interface invisible to COM by changing the accessibility to internal (Friend in Visual Basic) or by applying the System.Runtime.InteropServices.ComVisibleAttribute attribute set to false.

Do not exclude a warning from this rule.

The following example shows an interface that violates the rule and an interface that satisfies the rule.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(False)>
Namespace InteroperabilityLibrary

   ' This interface violates the rule.
   <ComVisibleAttribute(True)> _ 
   Public Interface IOverloadedInterface

      Sub SomeSub(valueOne As Integer)
      Sub SomeSub(valueOne As Integer, valueTwo As Integer)

   End Interface

   ' This interface satisfies the rule.
   <ComVisibleAttribute(True)> _ 
   Public Interface INotOverloadedInterface

      Sub SomeSub(valueOne As Integer)
      Sub AnotherSub(valueOne As Integer, valueTwo As Integer)

   End Interface

End Namespace

Community Additions

© 2015 Microsoft