.netspecificationscls

What is the purpose of the CLS in the .NET framework?


I'm confused about the purpose of the CLS (Common Language Specification) in the .NET Framework.

My understanding is that, with .NET, we can write a library with one language and use it in another language, and that the CLR enables this functionality. I do know that the purpose of the CLS is to fully interact with other objects regardless of the language they were implemented in.

What is the CLS exactly; what is its purpose?


Solution

  • The CLS is a guide-line intended for developers of components, as well as compiler-writers. It specifies what is allowed and what is not allowed in order to generate components, and build support for languages, in such a way that they are portable - and fully compatible to be consumed/interacted with from all CLS-compliant languages that can run in the CLR.

    While the CLR has specifications that are exposed and enforced by the implementation. The CLS is just a guideline. You can still write components that break the CLS, but will work fine in the CLR. But in that case they might not be inter-operable with certain languages.

    Obviously, the CLS is very important for compiler writers and language designers. But even as a component developer, it's important to stay within the lines of the CLS if you're striving for full inter-operability.