I've just upgraded
- .net 7 blazor server asp.net app to .NET 8
- Microsoft.Identity.Web nuget from 1.x to 2.x
and I'm getting exception from app.Build():
'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Sylex.ISYS.SharepointPortal.ISharePointClientContextFactory Lifetime: Scoped ImplementationType: Sylex.ISYS.SharepointPortal.SharePointClientContextFactory': Could not load type 'Microsoft.Identity.Web.ITokenAcquisition' from assembly 'Microsoft.Identity.Web, Version=2.16.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'.)
Here is the code that worked before:
builder.services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddScheme<AuthenticationSchemeOptions, BasicAuthenticationHandler>("Basic", null)
.AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(sharepointScopes)
.AddDistributedTokenCaches();
builder.Services.AddScoped<ISharePointClientContextFactory, SharePointClientContextFactory>(); //this type uses ITokenAquisition

I had a test in my side and it worked for me to use
ITokenAcquisitionto generate access token. I'm usingMicrosoft.Identity.Web with version 2.16.0.I'm afraid the issue is related to how we migrate from .net 7 to .net 8. I have a detailed steps about how I migrate in this answer before testing
ITokenAcquisition.