CLSCompliant Attribute

While developing a library in .Net which could be used by another programming language than it was originally designed in, it is important to remember that the .Net Languages offers a subset of CLR/CTS while offering a superset of CLS. And, if you want to develop a library that could be used by any programming language supported by .Net, you have additional responsibility to ensure that your code doesn’t take of care of any features outside the CLS.

Thankfully, .Net provides us an easier way to check the same using the CLSCompliant Attribute.

[assembly: CLSCompliant(true)]
namespace ConsoleApp3
    public class TestClass
        public int Method1() => 1;
        public int method1() => 2;
        private int mEthod1() => 3;

The above code would raise warning “Warning CS3005 Identifier ‘TestClass.method1()’ differing only in case is not CLS-compliant” to help us identify the non-compliance. Do note that mEthod1 doesn’t raise a warning as it is a private method and is not exposed outside the assembly.