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

IntelliSense confused by Action<> overloads #63339

Closed
datvm opened this issue Nov 15, 2021 · 9 comments
Closed

IntelliSense confused by Action<> overloads #63339

datvm opened this issue Nov 15, 2021 · 9 comments
Assignees
Labels
Area-IDE Bug IDE-IntelliSense Completion, Signature Help, Quick Info Resolution-By Design The behavior reported in the issue matches the current design
Milestone

Comments

@datvm
Copy link

datvm commented Nov 15, 2021

Description

I was trying to create a Windows Service in .NET 6 following this documentation.

I want to read the settings from appsettings.json so I added the following code:

IHost host = Host.CreateDefaultBuilder(args)
    .UseWindowsService(options =>
    {
        options.ServiceName = "My Service";
    })
    .ConfigureServices(services =>
    {
        var settings = new ScriptOptions(); // ScriptOptions is just a POCO class
        services.Configuration.Bind(settings);

        services.AddHostedService<WindowsBackgroundService>();
    })
    .Build();

As you can see, IntelliSense seems to recognize there is Configuration property in services (instance of IServiceCollection instead of HostBuilderContext).

image

However the code wouldn't compile because IServiceCollection does NOT have Configuration property, but HostBuilderContext does.

I realized ConfigureServices method has 2 overload (actually there is one, the other is extension method):

// Default Method
IHostBuilder ConfigureServices(Action<HostBuilderContext, IServiceCollection> configureDelegate);

// Extension Method
public static IHostBuilder ConfigureServices(this IHostBuilder hostBuilder, Action<IServiceCollection> configureDelegate)

So in the case of using Extension Method, somehow IntelliSense thought services is HostBuilderContext.

Note: I already fixed my problem, just want to report strange behavior of IntelliSense that made me spend a lot of time figuring out why my code couldn't compile. Here's the fix if anyone is interested:

    // Add ctx parameter
    .ConfigureServices((ctx, services) =>
    {
        var settings = new ScriptOptions();
        ctx.Configuration.Bind(settings);

        services.AddHostedService<WindowsBackgroundService>();
    })

Configuration

  • Which version of .NET is the code running on? 6.0
  • What OS and version, and for Linux, what distro? Windows 11 Pro
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? I am not sure, probably not
  • If you're using Blazor, which web browser(s) do you see this issue in? None

Regression?

I don't know

Other information

Microsoft Visual Studio Community 2022
Version 17.0.0
VisualStudio.17.Release/17.0.0+31903.59
Microsoft .NET Framework
Version 4.8.04161

Installed Version: Community

@eiriktsarpalis
Copy link
Member

cc @mairaw

@mairaw
Copy link
Contributor

mairaw commented Nov 16, 2021

This is not related to the tutorials but instead it's an IntelliSense issue. @jaredpar @terrajobst would you know who can help with this?

@eiriktsarpalis
Copy link
Member

@datvm would it be possible to share a repo with instructions on how to reproduce the issue? We can try to take a look.

@datvm
Copy link
Author

datvm commented Nov 17, 2021

@eiriktsarpalis Hi, just create a new project with Worker template and you have the problem immediately in Program.cs file:

image

Github Repo if you still need it.

It seems to list all members of HostBuilderContext, for example, HostingEnvironment is listed as well though it should not:

image

@datvm
Copy link
Author

datvm commented Jun 8, 2022

Hi is there any update on this issue? It's still happening today (VS 2022 17.2.3)

image

@mairaw
Copy link
Contributor

mairaw commented Jun 9, 2022

Since this is happening in VS, you might be able to get better support if you file the issue through Visual Studio Help menu.

@datvm datvm closed this as completed Jun 10, 2022
@genlu genlu transferred this issue from dotnet/core Aug 11, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 11, 2022
@genlu genlu reopened this Aug 11, 2022
@genlu
Copy link
Member

genlu commented Aug 11, 2022

Related VS feedback ticket https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1590331

@dibarbet dibarbet added Bug IDE-IntelliSense Completion, Signature Help, Quick Info and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 15, 2022
@dibarbet dibarbet added this to the 17.4 milestone Aug 15, 2022
@genlu genlu modified the milestones: 17.4, 17.6 Jan 11, 2023
@datvm
Copy link
Author

datvm commented Mar 6, 2024

I can confirm this is no longer an issue testing at v17.9.2. Do you want to close this?

@sharwell
Copy link
Member

sharwell commented Mar 6, 2024

@datvm In general, the behavior described above is by design. In the face of incomplete code, the compiler may or may not be able to complete its overload resolution process down to a single set of types. When this step fails to produce a unique result, completion lists will attempt to include the union of possible results to best allow the user to bring the code from an incomplete state to a valid complete state.

@sharwell sharwell closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
@sharwell sharwell added the Resolution-By Design The behavior reported in the issue matches the current design label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug IDE-IntelliSense Completion, Signature Help, Quick Info Resolution-By Design The behavior reported in the issue matches the current design
Projects
None yet
Development

No branches or pull requests

6 participants