I just came across the following problem : A colleague of me has created a server control. After dropping this control on my ASP.Net page, following line of code is added to the generated code section :
protected <assembly> <controlname On form>;
When compiling we got following error :
"page.aspx.cs(19): Type of '<control>' is not CLS-compliant"
My colleague doesn't receive this message. At first, just to have a quick, working solution, we put following line above every line :
[CLSCompliant(false)]
In this case, my project compiles and I could put it on the test server. A few days later, I had some time to look deeper into this problem.
It seems that to make an assembly CLS Compliant, your 3-letter mnemonics must be Pascal case (Only 2 characters are all uppercase). Also several checks are done :
- Class and member names cannot differ only by case. For example, you can't have one property named Counter and another named counter. This is important for cross-language compatibility since VB .NET isn't case sensitive.
- Overloaded class methods cannot differ only by out or ref parameter designations.
- Publicly exposed members cannot start with an underscore ( _ ).
- Operators can't be overloaded
- Unsigned types can't be part of the public interface of a class
The reason why my colleague doesn't need the CLS compliant = false in his code, is because he has the code of the server control in his project.
To solve my problem : He just need to add set the attribute [assembly: CLSCompliant(true)].
When this is done, and I have the new DLL, I can delete the line to set the CLS Compliant false. So an easy solution. Also if this attribute isn't set, It's possible that the control can't be used within any .Net language.
Remark : When using VB.Net, you are lucky because VB.Net doesn't check for the CLS Compliance.