'Arrays as attribute arguments is not CLS-compliant' warning, but no type information given
Asked Answered
S

3

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?

Steinway answered 28/10, 2009 at 14:50 Comment(1)
Did you find an easy way of finding where the warning was being caused?Hazlip
B
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.

Bibb answered 28/10, 2009 at 14:56 Comment(1)
But the attribute is internal to the assembly - not publically accessible. That should not affect the CLS compliance.Steinway
R
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.

Reiterate answered 9/12, 2010 at 17:37 Comment(1)
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.Reiterate
S
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.

Savior answered 23/8, 2012 at 18:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.