-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CA1861 makes a breaking suggestion for attribute arguments #7205
Comments
Since this issue is already fixed, I suggest you install the |
I can confirm it is fixed for us in that preview package. From the dates it looks like the fix just missed the cut for version 8. Does this mean the fix won't be in the SDK until .NET 9? Is there any likelihood of a patch release for version 8? There were several for version 7. |
I'm not sure if analyzers are included in the patch releases of an SDK. Someone from the team would need to comment on that. |
Even a patch release just of the analyzers might be helpful. It was that I was thinking of more when I said about the ones for version 7. |
This NuGet package contains the fix: https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers/9.0.0-preview.24072.1 |
Can this be closed now? |
I just ran into this same issue. Using the nuget package |
@Morilli which precise version 9.0 did you use before .NET 9? A false-positive fix may have come after the version shipped with .NET 9. |
Testing this again, I cannot reproduce this inspection again with any version of the .NET 9 SDK, just the .NET 8 one. So it looks like some inspection results may have been cached incorrectly or I had forgotten to switch back to the .NET 9 SDK while testing. All versions of the .NET 9 SDK look fine for me now. |
Analyzer
Diagnostic ID: CA1861:
Avoid constant arrays as arguments
Analyzer source
Version: SDK 8.0.101
Describe the bug
CA1861 triggers when an array is initialized as an argument to an attribute. This shouldn't happen, as attributes require constant arguments. Therefore, the CA1861 suggestion of initializing a static array is a breaking suggestion, leading to code that does not compile.
Found it while writing an xUnit test:
If you apply the suggested correction, you get CS0182 (An attribute argument must be a constant expression,
typeof
expression or array creation expression of an attribute parameter type), which is a compilation error.This issue seems to be related to #7033
Steps To Reproduce
Initialize an array for an attribute argument.
Expected behavior
No suggestion, warning, or error should be made.
Actual behavior
A CA1861 suggestion is made.
Additional context
VS Code + C# Dev Kit 1.3.10
.NET 8.0.101
The text was updated successfully, but these errors were encountered: