Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →To make a C# library’s public API CLS-compliant, declare that intent with [assembly: CLSCompliant(true)], build and review the resulting warnings, and explicitly mark any unavoidable non-compliant public types or members with [CLSCompliant(false)]. Offer a compliant alternative where practical. CLS rules govern the component’s public interface—not its private implementation—and help make APIs consumable by languages that support the Common Language Specification.
What CLS compliance means for a C# library
The Common Language Specification (CLS) defines rules for features exposed by components so that code written in different CLS-supporting languages can consume them. For a library author, the key boundary is the public API: private implementation details do not have to comply. Microsoft explains this distinction in its language-independence guidance.
As an Amazon Associate I earn from qualifying purchases.
CLS compliance is therefore an interoperability design goal, not a requirement that every implementation detail use a restricted subset of C#. It is especially relevant when you intend other .NET languages to use your library. A C#-only API may still choose language-specific features, but those features can limit which languages can use the affected public surface.
Free tools Windows power users keep installed
One-click scans. No signup required.
Declare compliance at the assembly level
When the assembly is intended to expose a CLS-compliant API, declare that intent once at assembly level:
#1 Best Overall
using System;
[assembly: CLSCompliant(true)]
namespace ExampleLibrary
{
public class Converter
{
public int ConvertValue(int value) => value;
}
}
Place the assembly attribute after any using directives and before declarations. The assembly’s compliance status is inherited by its contained types and members unless you explicitly identify an exception. Microsoft documents the attribute’s behavior in the CLSCompliantAttribute API reference.
Build the project and review compiler warnings about declarations that are presumed compliant but violate CLS rules. Treat warnings as useful diagnostics, not as a complete audit: Microsoft notes that some rules are enforced by compilers even without the attribute, and the selected examples in its overview are not the complete specification.
Rank #2
Review the whole public surface
Check more than method parameters. Review public and protected types and members, including names, fields, properties, method signatures, enum definitions, generic declarations, interfaces, events, and exception types. The following are practical warning signs:
- Identifiers that differ only by case: Names such as
Personandpersoncan collide in case-insensitive languages, so they are not CLS-compliant as a public API. - Unsigned types in public signatures: Microsoft gives a public method using
UInt32as an example of a non-compliant declaration. Do not assume every C# primitive type is suitable for a shared language-facing API. - Enum backing types: CLS-compliant enum underlying types are
Byte,Int16,Int32, orInt64. An enum backed byUInt32is a non-compliant example. - Interface members: The Microsoft overview lists static methods and fields on CLS-compliant interfaces as disallowed.
- Thrown exceptions: Throw
System.Exceptionor a type derived from it. - Generics and events: Rules also cover matters such as nested generic type parameters, generic type naming, and event naming patterns. Validate the exact design against the standard rather than relying on a short checklist.
Microsoft’s overview describes selected rules and points to ECMA-335, Partition I, Clauses 7–11—especially Clause 11—for the full rule set. Consult that normative text when a public API design depends on an edge case.
Isolate exceptions and offer a compliant alternative
If a useful public feature cannot be made CLS-compliant, mark the affected public type or member explicitly and, where feasible, provide a compliant alternative. For example:
using System;
[assembly: CLSCompliant(true)]
public class IdentifierParser
{
public int Parse(string value) => int.Parse(value);
[CLSCompliant(false)]
public uint ParseUnsigned(string value) => uint.Parse(value);
}
Document the compliant route so consumers using other CLS-supporting languages can find it. A member cannot be declared compliant when its containing type is non-compliant; mark the actual exception at the appropriate public type or member boundary.
Rank #4
CLSCompliantAttribute can be applied at several program-element targets, but applying it to a parameter or return value has no effect: Microsoft’s API reference says those applications are ignored. Use the attribute to state assembly intent and identify non-compliant assemblies, types, or members—not to annotate individual arguments or return values.
A practical compliance workflow
- Set the interoperability goal. Decide whether consumers in other CLS-supporting .NET languages are a supported audience.
- Declare the default. Add
[assembly: CLSCompliant(true)]afterusingdirectives and before declarations. - Build and review diagnostics. Investigate warnings on public declarations, then manually inspect the full public surface rather than assuming a clean build proves compliance.
- Resolve each exception deliberately. Redesign the API for compliance when practical; otherwise isolate the non-compliant type or member with
[CLSCompliant(false)]and document a compliant alternative where feasible. - Check the complete rules for edge cases. Use ECMA-335, Partition I, Clauses 7–11, when the Microsoft overview does not settle a design question.
What the attribute can—and cannot—tell consumers
The attribute communicates an element’s stated compliance status, with status flowing from assembly to types and from types to members. It does not itself redesign an incompatible signature or guarantee that every language compiler or toolchain will behave identically. Use compiler diagnostics alongside deliberate API review, and validate version-sensitive edge cases against the target standard and toolchain.
Quick Recap
Best Value
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.




