Home > front end >  IApplicationBuilder does not contain a definition for UseAzureAppConfiguration
IApplicationBuilder does not contain a definition for UseAzureAppConfiguration

Time:10-19

I've been trying to implement feature managament in my Blazor app following this and that but for some reason my program refuses to accept "UseAzureAppConfiguration" even though I should have the proper usings and packages.

This is my Startup.cs:

using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
using Microsoft.FeatureManagement;

namespace OreNoAppu
{
    public class Startup
    {
        public IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"));
            services.AddControllersWithViews().AddMicrosoftIdentityUI();

            // By default, all incoming requests will be authorized according to the default policy
            services.AddAuthorization(options => options.FallbackPolicy = options.DefaultPolicy);

            services.AddRazorPages();
            services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
            services.AddFeatureManagement();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days.You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseAzureAppConfiguration();     // "Does not contain definition" error.

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
    }
}

These are my nugets:

  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.4.1" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
    <PackageReference Include="BlazorPro.Spinkit" Version="1.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.4" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.4" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="4.5.0" />
    <PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.4.0" />
    <PackageReference Include="Microsoft.Identity.Web" Version="1.1.0" />
    <PackageReference Include="Microsoft.Identity.Web.UI" Version="1.1.0" />
  </ItemGroup>

Anyone have any idea why it can't find the method?

CodePudding user response:

Azure App Configuration helps to manage application settings and control their access centrally. It’s built on the simple concept of key-value pairs, and this service provides manageability, availability, and ease-of-use.

To solve the problem you are facing please check if you are using the right library and also check if you are having the following NuGet packages from Microsoft to work with an Azure App Configuration resource and the ability to use Feature Flags in the project.

Microsoft.Azure.AppConfiguration.AspNetCore Microsoft.Extensions.Configuration.AzureAppConfiguration Microsoft.FeatureManagement

As you have added FeatureManagement by using statement in Startup.cs and inside of ConfigureServices(...) added the ability to use it. Check if have modified the Program.cs and replaced the creation of default host builder with one that uses Azure App Configuration as shown below.

public  static  IHostBuilder CreateHostBuilder(string[] args) =>
  Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
     webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
     {
        var  settings = config.Build(); 
        config.AddAzureAppConfiguration(options => { 
            options.Connect(Environment.GetEnvironmentVariable("ConnectionString")) 
                    .ConfigureRefresh(refresh => { 
                            refresh.Register("Settings:Sentinel", refreshAll: true).SetCacheExpiration(new  TimeSpan(0, 1, 0)); 
                         }) 
                    .UseFeatureFlags(); 
        }); 
      }) 
      .UseStartup<Startup>());

Check this How to Add Azure App Configuration and Feature Flags into Blazor in .Net 5 document for detailed step by step explanation with example.

For more information also check the following documentations :

  • Related