Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting CLS compliance for a .NET assembly

Setting CLS compliance for an entire .NET assembly is possible. But how is it actually done? E.g. with Visual Studio 2008?

like image 909
Peter Mortensen Avatar asked Apr 21 '09 20:04

Peter Mortensen


People also ask

Which is not a CLS compliant language?

CLS compliance has to do with interoperability between the different . NET languages. The property is not CLS compliant, because it starts with an underscore and is public (note: protected properties in a public class can be accessed from outside the assembly).


2 Answers

Visual Studio adds a directive for the compiler, and the compiler checks the code for some more strict rules than in the native programming language.

You can add the CLS compliant attribute to all your project by adding the assembly level attribute

[assembly: CLSCompliant(true)] 

anywhere in your project, generally in the assemblyinfo.cs file.

If the line using System; is not at the top of the file, add it. Or, use the long form:

[assembly: System.CLSCompliant(true)] 
like image 144
pocheptsov Avatar answered Sep 19 '22 10:09

pocheptsov


You need to add this line to one of your source files:

[assembly: System.CLSCompliant(true)] 

More info on CLS compliant code here.

Normally you put this in assemblyinfo.cs

like image 26
Michael Avatar answered Sep 20 '22 10:09

Michael