Skip to content
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

After upgrading VS to 17.5.0 I'm getting CA1825 warnings in attributes #6500

Closed
JuanZamudioGBM opened this issue Feb 22, 2023 · 5 comments
Closed

Comments

@JuanZamudioGBM
Copy link

JuanZamudioGBM commented Feb 22, 2023

Analyzer

Diagnostic ID: CA1825: Avoid zero-length array allocations

Analyzer source

SDK: Built-in CA analyzers in .NET 6 SDK

Version: SDK 6.0.406

Describe the bug

Updated my installation to 17.5.0 then restarted my PC, after that I compiled my solution and saw CA1855 warnings on the Controllers in the Produce attributes:
[Produces(MediaTypeNames.Application.Json)]

Expected behavior

No warnings

Actual behavior

CA1825 warnings on attributes.

Additional context

Building the solution with the CLI using dotnet build builds correctly.
I'm targeting net6 using the lang version 10.

@yaakov-h
Copy link
Member

Me too, I'm seeing this in my Analyzers projects when declaring [DiagnosticAnalyzer(LanguageNames.CSharp)]. How ironic.

@deanmarcussen
Copy link

deanmarcussen commented Feb 23, 2023

we are also seeing this with [Bind] attributes on controllers.

public async Task<IActionResult> CreatePost([Bind(Prefix = "savebutton")] string save, VisualizationAdminCreateViewModel model)

also targeting net6

@yaakov-h
Copy link
Member

hmm, it looks like this should have been fixed in #6114, and the Analyzer already bails out if the array allocation is in an attribute or is a compiler-generated params array, and all three examples above meet both criteria.

@333fred is this perhaps a Roslyn issue rather than an Analyzer bug?

@333fred
Copy link
Member

333fred commented Feb 24, 2023

See the note on false positives in https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1825#when-to-suppress-warnings.

@333fred 333fred closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
@333fred
Copy link
Member

333fred commented Feb 24, 2023

You'll need to either upgrade the version of analyzers you are using, or suppress these false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants