Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

Do not use AutoDual ClassInterfaceType







Breaking Change


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.

using System;
using System.Runtime.InteropServices;

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

   public interface IExplicitInterface
      void SomeMethod();

   public class ExplicitInterface : IExplicitInterface
      public void SomeMethod() {}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.