Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

CA1822 false positive for C#14 extension method #7646

Closed

Description

@znakeeye

Creat a new project and target .NET 10 etc.

<Project>
  <PropertyGroup>
    <Nullable>enable</Nullable>
    <LangVersion>preview</LangVersion>
    <TargetFramework>net10.0</TargetFramework>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <AnalysisMode>All</AnalysisMode>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
  </PropertyGroup>
</Project>

VS incorrectly suggests that the method below can be static. It cannot.

internal static class StringExtensions
{
    extension(string instance)
    {
        public bool L33t() => instance.Length == 1338;
    }
}

Image

Relates to extensions (test plan dotnet/roslyn#76130)

Activity

  1. CyrusNajmabadi commented on Jul 24, 2025

    @CyrusNajmabadi

    Hitting this here: dotnet/roslyn#79550

  2. jjonescz commented on Jul 25, 2025

    @jjonescz
    Member

    Fixed by #7739.

  3. Frulfump commented on Jul 25, 2025

    @Frulfump

    Fixed by #7739.

    Which release will include the fix?

  4. jjonescz commented on Jul 25, 2025

    @jjonescz
    Member

    If I understand correctly, these analyzers ship in the SDK, so that would be rc.1 probably. Or you can maybe install this manually? https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet10/NuGet/Microsoft.CodeAnalysis.NetAnalyzers/overview/10.0.0-preview.25375.1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions