AuthenticationBuilder does not contain a definition for AddAzureAd

13,883

Solution 1

I had the exact same loss of time with something as stupid as not adding the reference. The answer to this question would be along the lines of:

 dotnet add package Microsoft.AspNetCore.Authentication.AzureAD.UI --version 2.2.0

Notice that you may have added another reference related to authentication but not the one you are having the problem about.

Solution 2

I had to add a using statement to my Startup file.

using Microsoft.AspNetCore.Authentication;
Share:
13,883
superninja
Author by

superninja

Updated on June 29, 2022

Comments

  • superninja
    superninja almost 2 years

    Im following a tutorial from here and trying to enable OpenId Connect using Azure Ad and here's the code that I am trying to add to the Startup.cs file.

        services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddAzureAd(options => Configuration.Bind("AzureAd", options))
            .AddCookie();
    

    But it has red underline for AddAzureAd and shows this error message:

    'AuthenticationBuilder' does not contain a definition for 'AddAzureAd' and no accessible extension method 'AddAzureAd' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)

    Steps I have tried:

    1. Clean and rebuild the solution
    2. restart visual studio

    But it doesnt fix the issue. Anyone knows what's the other reason that causes this?

  • Eru
    Eru over 3 years
    this unfortunately did not help for me :(