CA1409: Com visible types should be creatable

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
RuleId CA1409
Category Microsoft.Interoperability
Breaking change Non-breaking

Cause

A reference type that is specifically marked as visible to Component Object Model (COM) contains a public parameterized constructor but does not contain a public default (parameterless) constructor.

Rule description

A type without a public default constructor cannot be created by COM clients. However, the type can still be accessed by COM clients if another means is available to create the type and pass it to the client (for example, through the return value of a method call).

The rule ignores types that are derived from System.Delegate.

By default, the following are visible to COM: assemblies, public types, public instance members in public types, and all members of public value types.

How to fix violations

To fix a violation of this rule, add a public default constructor or remove the System.Runtime.InteropServices.ComVisibleAttribute from the type.

When to suppress warnings

It is safe to suppress a warning from this rule if other ways are provided to create and pass the object to the COM client.

CA1017: Mark assemblies with ComVisibleAttribute

See also