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

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

Open
just-ero opened this issue Nov 20, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@just-ero
Copy link

just-ero commented Nov 20, 2024

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 20, 2024
@just-ero
Copy link
Author

just-ero commented Nov 20, 2024

Note: The extension method is picked up while typing (typing c.M will contain M from the extension namespace) and does add the required namespace upon accepting the suggestion.

However, this is also not always the case. I have not been able to figure out the conditions of this behavior.

@CyrusNajmabadi CyrusNajmabadi added this to the 17.13 milestone Nov 20, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 20, 2024
@CyrusNajmabadi
Copy link
Member

@genlu can you ptal.

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

No branches or pull requests

3 participants