Skip to content

CA1416 doesn't work when Microsoft.CodeAnalysis.NetAnalyzers is referenced directly with EnableNETAnalyzers=false #53125

Closed

Description

@amaltinsky

When a project has a dependency on Microsoft.CodeAnalysis.NetAnalyzers v10.0.103 and EnableNETAnalyzers is set to false, CA1416 warnings aren't being triggered when they should (reproduction code).

This didn't use to be the case with Microsoft.CodeAnalysis.NetAnalyzers v8.0.0. In fact, adding a dependency on Microsoft.CodeAnalysis.NetAnalyzers v8.0.0 used to set EnableNETAnalyzers to false to prevent collisions between the SDK's built-in analyzers and the package-provided ones.

Activity

  1. amaltinsky commented on Feb 24, 2026

    @amaltinsky
    Author

    I believe that this should be tagged as Microsoft.CodeAnalysis.NetAnalyzers

  2. amaltinsky commented on Mar 2, 2026

    @amaltinsky
    Author
  3. jjonescz commented on Mar 2, 2026

    @jjonescz
    Member

    I believe that this should be tagged as Microsoft.CodeAnalysis.NetAnalyzers

    Not sure about that, given this is about the property EnableNETAnalyzers, it might be more "SDK area" rather than "analyzers area", but added the label anyway.

  4. amaltinsky commented on Mar 2, 2026

    @amaltinsky
    Author

    @jjonescz
    Thanks for that.

    I believe that the issue could be related to the packaging of Microsoft.CodeAnalysis.NetAnalyzers nuget. I further nailed down the breakage as happening between 10.0.0-preview.25380.108 (produces the warning correctly) and 10.0.100-rc.1.25451.107 (doesn't produce it anymore). The preview version has additional directories like "buildTransitive", "rulesets" and others, while the RC version does not:

    Image Image
  5. amaltinsky commented on Mar 4, 2026

    @amaltinsky
    Author

    I've had some more time to spend on this, and found that what's stopping CA1416 from working are some missing CompilerVisibleProperty items which used to be set by buildTransitive/Microsoft.CodeAnalysis.NetAnalyzers.targets.

  6. KalleOlaviNiemitalo commented on Mar 4, 2026

    @KalleOlaviNiemitalo
    Contributor

    @amaltinsky if you were expecting me to label this issue — I don't have access. And I feel more relaxed that way.

  7. amaltinsky commented on Mar 4, 2026

    @amaltinsky
    Author

    @KalleOlaviNiemitalo And I fully support your relaxation :)
    I don't know who has what permissions, and was just trying to get some eyeballs on this issue from people involved with Roslyn analyzers.

  8. cremor commented on May 12, 2026

    @cremor

    I believe that the issue could be related to the packaging of Microsoft.CodeAnalysis.NetAnalyzers nuget.

    Related: #54046

  9. added this to the 11.0.1xx milestone on Aug 23, 2026
  10. jeffhandley commented on Aug 23, 2026

    @jeffhandley
    Member

    Thanks for reporting this, @amaltinsky. I've confirmed this was indeed regressed in .NET 10.

  11. amaltinsky commented on Aug 27, 2026

    @amaltinsky
    Author

    Hi @jeffhandley

    Thank you for confirming. I see you've added the 11.x milestone. Will this not be fixed in 10.x? It's at least one analyzer completely broken, potentially more.

    Also, is something going to be done to address the lack of testing in this area? This isn't exactly a subtle bug, and could have easily been caught.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions