'Arrays as attribute arguments is not CLS-compliant' warning, but no type information given
When compiling my solution, I ge开发者_JAVA技巧t 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?
CS3016.
If you have an attribute which takes an array as argument and the project is marked as CLSCompliant you will get this warning.
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.
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.
精彩评论