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

[Bug] Cannot resolve scoped service when Debug via Visual Studio on Windows - Works using Linux Container #128

Open
Johno-ACSLive opened this issue May 13, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Johno-ACSLive
Copy link

Which version of Microsoft Identity Abstractions for dotnet are you using?
Microsoft Identity Abstractions version 5.3.0 via Microsoft.Identity.Web.DownstreamApi version 2.18.1

Is this a new or an existing app?
New app

Repro

Debug an ASP.NET 8.0 application using multiple IDP's and Azure Web PubSub.

// IDP 1
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("EntraExternalID"))
                .EnableTokenAcquisitionToCallDownstreamApi()
                .AddDownstreamApi("ServiceA", builder.Configuration.GetSection("ServiceA"))
                .AddDownstreamApi("ServiceB", builder.Configuration.GetSection("ServiceB"))
                .AddInMemoryTokenCaches();

// IDP 2
builder.Services.AddAuthentication().AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("EntraID"), "EntraID");

// Add Web PubSub Service Client
builder.Services.AddWebPubSub(options =>
{
    var config = builder.Configuration.GetSection("Config").Get<Configuration<Config>>();
    options.ServiceEndpoint = new WebPubSubServiceEndpoint(config.ConnectionString);
}).AddWebPubSubServiceClient<webpubsub>();

// standard init in between e.g. var app = builder.Build();

// Further down map web pubsub event handler
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapWebPubSubHub<webpubsub>("/eventhandler/{*path}");
app.Run();

Expected behavior
Error is not observed when debugging on Windows via Visual Studio.

Actual behavior
The call to app.MapWebPubSubHub<webpubsub>("/eventhandler/{*path}"); triggers System.InvalidOperationException: 'Cannot resolve scoped service 'Microsoft.Identity.Abstractions.IDownstreamApi' from root provider.' only when debugging via Visual Studio (latest version - 17.9.6) on Windows. When run in a Linux Container the app runs fine.

Possible solution
N/A

@jmprieur
Copy link
Contributor

jmprieur commented Jul 24, 2024

What is WebAppPubSubHub? would it require IdWeb as a singleton?
You probably want to move this bug to Microsoft.IdentityWeb.Web btw?

@jmprieur jmprieur added question Further information is requested and removed needs attention untriaged labels Jul 24, 2024
@Johno-ACSLive
Copy link
Author

The SDK Azure.Messaging.WebPubSub is for the Azure Web PubSub service. This is workign when running via a Linux docker container, just not when debugging on Windows using Visual Studio so I don't think changing ID Web to a singleton will fix this. It depends on how things are being registered under the hood.

It's possible to be an issue in Microsoft.Identity.Web.DownstreamApi - from memory IDownstreamApi had been moved around and changed in the past so I don't recall why I logged it to this repo.

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

No branches or pull requests

2 participants