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

与世无争的帅哥 提交于 2019-12-30 17:29:06

问题


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?


回答1:


CS3016.

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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1637764/arrays-as-attribute-arguments-is-not-cls-compliant-warning-but-no-type-inform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!