Skip to content

Fix Add import is not suggested for extension methods defined in projects targeting a different framework than the project using the extension method #75991

@just-ero

Description

@just-ero

Version Used

Compiler: 4.13.0-2.24565.3 (c267dc9)
.NET: 9.0.100
Visual Studio Code: 1.95.3, f1a4fb101478ce6ec82fe9627c43efbf9e98c813, x64
C# Extension: v2.57.28
C# Dev Kit Extension: v1.14.8

Steps to Reproduce

  1. Create or open a C# solution in Visual Studio Code (Visual Studio untested).
  2. Create two projects:
    • Project 1:
      <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
          <TargetFramework>net8.0</TargetFramework>
        </PropertyGroup>
      </Project>
    • Project 2:
      <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
          <TargetFramework>net9.0</TargetFramework>
        </PropertyGroup>
        <ItemGroup>
          <ProjectReference Include="path/to/Project 1" />
        </ItemGroup>
      </Project>
  3. Add the following code wherever syntactically applicable in Project 1:
    namespace Project1;
    
    public class C;
    namespace Project1.Extensions;
    
    public static class CExtensions {
      public static void M(this C c) { }
    }
  4. Add the following code wherever syntactically applicable in Project 2:
    using Project1;
    
    namespace Project2;
    
    class Repro {
      void M(C c) {
        c.M();
      }
    }
  5. Attempt to apply Add import on c.M().

Expected Behavior

The fix is suggested.

Actual Behavior

It is not.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions