To enable CLS compliance checks for a C# library, add [assembly: CLSCompliant(true)] to a compiled source file, then build the project and review the compiler warnings on its public API. This declares the assembly’s intent to expose a CLS-compliant API; it does not change signatures or guarantee that every public element complies.
What CLS checks do—and when they matter
The Common Language Specification (CLS) sets rules for names, data types, and other API features so components can be used across languages that target .NET. The checks are most useful when you are building a library for consumers who may use different .NET languages. An application that does not expose APIs for other developers may have little reason to enforce CLS compliance on its own elements. Microsoft’s language-independence guidance explains that the compiler detects noncompliant elements presumed to be compliant and emits warnings.
As an Amazon Associate I earn from qualifying purchases.
Enable the assembly-level declaration
Put the assembly attribute in a source file that is compiled into the assembly. A separate AssemblyInfo.cs file is one option; it can also go in another compiled C# source file. Place it after any using directives and before namespace or type declarations:
Free tools Windows power users keep installed
One-click scans. No signup required.
using System;
[assembly: CLSCompliant(true)]
The attribute applies at assembly scope. A module-level attribute does not enable checking for an assembly target; the compiler reports that case with CS3012. Microsoft’s CS3012 reference describes the diagnostic.
#1 Best Overall
Build, review warnings, and handle exceptions
- Decide whether the library should make a cross-language API commitment. The declaration is intended for reusable components, not as a general-purpose switch for every .NET application.
- Add
[assembly: CLSCompliant(true)]. Ensure the file containing it is included in the assembly build. - Build the project and inspect compiler warnings. Review publicly exposed types and members that violate CLS rules while being presumed compliant.
- Adjust the API where practical. If a noncompliant public element is necessary, mark it with
[CLSCompliant(false)]and, where possible, offer and document a CLS-compliant alternative.
The assembly attribute declares the intended contract; it does not rewrite an API or prove that the API meets every CLS rule. Explicitly identified noncompliant elements can exist in an assembly marked compliant. Compliance status is inherited through containing declarations unless explicitly overridden where permitted. See Microsoft’s CLS guidance and the CS3013 reference.
Quick Recap
Best Value
Rank #4
Rank #2
CLS compiler checks and CA1014 are different
| Mechanism | What it checks | How to use or configure it | Current status |
|---|---|---|---|
| Assembly CLS attribute and compiler behavior | Applicable noncompliant API elements that are presumed compliant. | Add [assembly: CLSCompliant(true)] in compiled source, then build and review compiler warnings. |
Activated by the assembly declaration; it is not controlled by CA1014’s default analyzer setting. Microsoft CLS guidance. |
| CA1014 code-analysis rule | Whether an assembly has a CLSCompliantAttribute. |
It is an analyzer rule, not the switch for compiler CLS warnings. | Microsoft lists CA1014 as disabled by default in .NET 10; the rule applies to C# and Visual Basic. CA1014 rule reference. |
Common diagnostic issues
- CS3012 — attribute placed on a module: Put the declaration at assembly scope to enable checking for an assembly target. CS3012 documentation.
- CS3014 — compliant member in an unmarked assembly: A member marked CLS-compliant without an assembly-level CLS declaration can trigger this warning. CS3014 documentation.
- CS3013 — added module has a mismatched CLS state: The compiler reports a mismatch between an added module and the assembly; the documented default for an added module is noncompliant. CS3013 documentation.
- Attribute is in the wrong position: Assembly and module attributes belong after
usingdirectives and before declarations. CS3012 documentation.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




