11

When compiling my solution, I get several warnings of the following:

warning CS3016: Arrays as attribute arguments is not CLS-compliant

No other information on what type is not compliant is given. In my projects I have some attributes that take params array arguments in their constructors, but they are all internal, and that shouldn't affect CLS-compliance. Why is this warning being given, and what type is it being given on?

T.S.
  • 18,195
  • 11
  • 58
  • 78
thecoop
  • 45,220
  • 19
  • 132
  • 189

3 Answers3

8

CS3016.

If you have an attribute which takes an array as argument and the project is marked as CLSCompliant you will get this warning.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 3
    But the attribute is internal to the assembly - not publically accessible. That should not affect the CLS compliance. – thecoop Oct 28 '09 at 15:45
3

I ran into this today. I had 4 instances of the warning showing up. I then found that I had the attribute decorating 4 public methods in that assembly. As I removed them one by one, the errors went away one by one.

Also, if you are OK with not being CLS compliant, you can put [CLSCompliant(false)] on the methods decorated with the attribute (or the class on which the methods are defined). Putting it on the offending attribute constructor/class doesn't do the trick. I guess this makes sense since ultimately the attribute is probably exposed outside the assembly as part of the public method's metadata.

Jim Counts
  • 12,535
  • 9
  • 45
  • 63
Brent
  • 31
  • 1
  • 4
    Also, if you are OK with not being CLS compliant, you can put [CLSCompliant(false)] on the methods decorated with the attribute (or the class on which the methods are defined). Putting it on the offending attribute constructor/class doesn't do the trick. I guess this makes sense since ultimately the attribute is probably exposed outside the assembly as part of the public method's metadata. – Brent Dec 09 '10 at 17:51
0

I ran into the same issue, and what I had to do was to use the "Find in Files" dialog in VS2010 select Use: Wildcards and in the Find What: text box, enter

\[*\(*\)\]

That produces a list of all attribute instances. Went one by one and I was able to identify and correct the warnings.

Mario
  • 659
  • 7
  • 12