Cleaning up C# compiler warning CS3016: Arrays as attribute arguments is not CLS-compliant [duplicate]
Possible Duplicate:
‘Arrays as attribute arguments is not CLS-compliant’ warning, but no type information given
I have some code, which generates this warning in开发者_Go百科 several places. I want to fix them, but I do not know where they are because the C# compiler does not report the line of the error (there is an open MS Connect issue for that).
Is there a tool, which can tell me where is the problematic code? IL level tool is fine, known the method name and declaring type is good enough.
You have declared a class like:
[SomeAttribute(new string[] { "foo", "bar" })
class SomeClass { }
or have declared an attribute like:
class SomeAttribute : Attribute
{
public SomeAttribute(string[] arr) { } // or another array
}
And all this is happening because your assembly is marked to be CLSCompliant:
[assembly:CLSCompliant(true)]
I'd adopt the following process:
- Identify the attributes that have arrays in their constructors (sophistication required to do this obviously depends on how many classes you have that derive from Attribute)
- Use the Visual Studio "Find All References" option on the attribute class constructors to find the things that are decorated with the attribute using arrays.
The first part should be fairly easy if the attributes in question are defined in your solution.
If the attributes are from a dependency then you might have to use a regex search to find the places where such attributes are used.
精彩评论