You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Diagnostic ID: CA1861: Avoid constant arrays as arguments
Analyzer source
Version: SDK 8.0.100
Describe the bug
A constant array in an attribute initializer produces diagnostic CA1861 but extracting the array into a static field is not possible due to language constraints.
Happens for other attributes, like NUnit.Framework.TestCaseAttribute where it would be:
[TestCase("a",new[]{"b"})]// false CA1861
A hillarious workaround is to write:
[Xunit.InlineData("a",(string[])["b"])]
where the cast (string[]) is needed only if the attribute class constructor in question takes a very general argument, like object. If the receiver already wants a concrete array, ["b"] without cast is sufficient.
@mavasani How roslyn analyzers are updated for users? Are they bound to version of VS or .NET SDK or what? This issue if fixed sor quite some time, but I still have this bug (VS 17.9P5, latest .NET 8 SDK). Very annoying...
Analyzer
Diagnostic ID: CA1861:
Avoid constant arrays as arguments
Analyzer source
Version: SDK 8.0.100
Describe the bug
A constant array in an attribute initializer produces diagnostic CA1861 but extracting the array into a static field is not possible due to language constraints.
Steps To Reproduce
Expected Behavior:
The array
new[] { "b" }
has no compiler warnings.Actual Behavior:
The array
new[] { "b" }
has a CA1861 warning but the code cannot be changed because no field is allowed in attribute syntax.The text was updated successfully, but these errors were encountered: