CA1014: Mark assemblies with CLSCompliantAttribute

TypeName

MarkAssembliesWithClsCompliant

CheckId

CA1014

Category

Microsoft.Design

Breaking Change

Non-breaking

Cause

An assembly does not have the CLSCompliantAttribute attribute applied to it.

Rule Description

The Common Language Specification (CLS) defines naming restrictions, data types, and rules to which assemblies must conform if they will be used across programming languages. Good design dictates that all assemblies explicitly indicate CLS compliance with CLSCompliantAttribute. If the attribute is not present on an assembly, the assembly is not compliant.

It is possible for a CLS-compliant assembly to contain types or type members that are not compliant.

How to Fix Violations

To fix a violation of this rule, add the attribute to the assembly. Instead of marking the whole assembly as noncompliant, you should determine which type or type members are not compliant and mark these elements as such. If possible, you should provide a CLS-compliant alternative for noncompliant members so that the widest possible audience can access all the functionality of your assembly.

When to Suppress Warnings

Do not suppress a warning from this rule. If you do not want the assembly to be compliant, apply the attribute and set its value to false.

Example

The following example shows an assembly that has the CLSCompliantAttribute attribute applied that declares it CLS-compliant.

Imports System

<assembly:CLSCompliant(true)>
Namespace DesignLibrary
End Namespace
using System;

[assembly:CLSCompliant(true)]
namespace DesignLibrary {}
using namespace System;

[assembly:CLSCompliant(true)];
namespace DesignLibrary {}

See Also

Reference

CLSCompliantAttribute

Concepts

Language Independence and Language-Independent Components