Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[assembly:CLSCompliant(true)]
namespace AttributeCLSComplaint
{
class Abc
{
UInt32 y;
[CLSCompliant(true)]
public UInt32 meth1()
{
UInt32 x = 10;ut
return x;
}
}
class Program
{
static void Main(string[] args)
{
Abc a = new Abc();
UInt32 x=a.meth1();
Console.WriteLine(x);
}
}

}

My theme is to use CLSCompliant Attribute over here; As needed, i wrote all the required attributes but am getting a warning: "CLS compliance checking will not be performed on AttributeCLSComplaint.Abc.meth1() because it is not visible from outside this assembly" by showing a warning symbol below: CLSComplaint(true) which is above meth1()..
Posted

1 solution

Basically, it tells you that the use of this attribute for the method meth1() makes no sense. It is invisible to the assembly using your assembly because its declaring class is invisible.

You should think about applications of this attribute. Are you sure you really need it? Basically, you tell the assembly that may use your assembly but written in a different language, that your assembly is CLS-compliant. That foreign language may be limited in the non-CLS-compliant features compared to your assembly; and it may create some problems. But do you really want to make provisions for such situations? Anyway, you only need to mark some separate types or members with this attributes if you want to develop a CLS-compilant set of API plus its extension which is not CLS-compliant; then you would mark a CLS-compilant subset with this attribute. Even if you want it, will it be practical? You could have a separate assembly referencing an assembly with common code which is not CLS-compliant (and explicitly mark all those assemblies as CLS-complient or not).

Another use case could be executing your code under alternative CLR implementation, other than .NET. Some runtime systems might be designed to load only the CLS-compliant assemblies. However, I don't know such implementations; they all go beyond the standard for CLS.

Please see:
http://msdn.microsoft.com/en-us/library/bhc3fa7f%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.clscompliantattribute.aspx[^],
http://forums.asp.net/t/1315820.aspx/1[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900