Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

COM visible type base types should be COM visible

TypeName

ComVisibleTypeBaseTypesShouldBeComVisible

CheckId

CA1405

Category

Microsoft.Interoperability

Breaking Change

DependsOnFix

A COM visible type derives from a type that is not COM visible.

When a COM visible type adds members in a new version, it must abide by strict guidelines to avoid breaking COM clients that bind to the current version. A type that is invisible to COM presumes it does not need to adhere to these COM versioning rules when it adds new members. However, if a COM visible type derives from the COM invisible type and exposes a class interface of ClassInterfaceType.AutoDual or AutoDispatch (the default), all public members of the base type (unless they are specifically marked as COM invisible, which would be redundant) are exposed to COM. If the base type adds new members in a subsequent version, any COM clients that bind to the class interface of the derived type might break. COM visible types should derive only from COM visible types to reduce the possibility of breaking COM clients.

To fix a violation of this rule make the base types COM visible or the derived type COM invisible.

Do not suppress a warning from this rule.

The following example shows a type that violates the rule.

using System;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
namespace InteroperabilityLibrary
{
   [ComVisible(false)]
   public class BaseClass
   {
      public void SomeMethod(int valueOne) {}
   }

   // This class violates the rule.
   [ComVisible(true)]
   public class DerivedClass : BaseClass
   {
      public void AnotherMethod(int valueOne, int valueTwo) {}
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft