question

JasonGaylord-1907 avatar image
1 Vote"
JasonGaylord-1907 asked AmrElgarhy answered

No Features Returned from Azure App Configuration

I followed the steps at https://docs.microsoft.com/en-us/azure/azure-app-configuration/quickstart-feature-flag-aspnet-core?tabs=core3x for getting a list of features. On my Home controller, if I call

 var features = featureManager.GetFeatureNamesAsync();

I don't see any features. Although, I have features setup. I do see that the app configuration resource in Azure is getting hit.

So, here are the steps I've followed:

  1. Created a new .NET Core MVC project targeting 3.1 (to eliminate the fact that .NET Core 5 may have issues)

  2. Add the Microsoft.Azure.AppConfiguration.AspNetCore and Microsoft.FeatureManagement.AspNetCore NuGet packages

  3. Update startup.cs > Configure > adding in app.UseAzureAppConfiguration();

  4. Update startup.cs > ConfigureServices > adding in services.AddFeatureManagement();

  5. In the Azure Portal, created a new Azure App Configuration resource in the free tier. Added a single feature called ShowAboutMe and set the value to On

  6. In the resource, go to AccessKeys and copy the primary read only key

  7. In my application, add a new key/value in appsettings.json called "AppConfigConnectionString" and set the value to the value I just copied.

  8. In Program.cs > CreateHostBuilder > added the following:

              Host.CreateDefaultBuilder(args)
                     .ConfigureAppConfiguration((context, builder) =>
                     {
                         var settings = builder.Build();
        
                         if (!string.IsNullOrEmpty(settings["AppConfigConnectionString"]))
                         {
                             builder.AddAzureAppConfiguration(options => {
                                 options.Connect(settings["AppConfigConnectionString"]);
                                 options.Select(KeyFilter.Any);
                                 options.UseFeatureFlags();
                             });
                         }
                     })
                     .ConfigureWebHostDefaults(webBuilder =>
                     {
                         webBuilder.UseStartup<Startup>();
                     });
    

  9. In Controllers\HomeController.cs, changed the top part of the controller class to resemble this:

          private readonly IFeatureManager _featureManager;
             private readonly ILogger<HomeController> _logger;
        
             public HomeController(ILogger<HomeController> logger, IFeatureManager featureManager)
             {
                 _logger = logger;
                 _featureManager = featureManager;
             }
        
             public IActionResult Index()
             {
                 var features = _featureManager.GetFeatureNamesAsync();
        
                 return View();
             }
    

  10. Set a breakpoint on the return View() line in the Index method, executed, and checked the results of features.

When navigating, I only see this response: System.Collections.Generic.IAsyncEnumerator<string>.Current = null

Any ideas what I can be missing? I have tried .NET Core 5 MVC and .NET Core 5 Razor Pages applications as well with no luck.

azure-app-configuration
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Note, I also tried to check a specific value and I'm using an await on the for loop:

                 var names = featureManager.GetFeatureNamesAsync();
    
                 await foreach (var v in names)
                 {
                     var x = v;
                 }
    
                 return await featureManager.IsEnabledAsync("ShowAboutMe");

Still no luck

0 Votes 0 ·
JasonGaylord-1907 avatar image
0 Votes"
JasonGaylord-1907 answered

After many failed attempts, I created a brand new Azure App Configuration resource. I noticed that like the above resource, this too seems to have a glitch within the portal. Notice the deployment name says 'NoMarketplace'

9137-nomarketplace.jpg

Then, I tried using the primary access key which then resulted in the following error:

9251-error.jpg

Finally, I used the secondary access key which worked.

Is there an issue with Azure resource provisioning?



nomarketplace.jpg (88.0 KiB)
error.jpg (122.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AshokTewatia-2318 avatar image
0 Votes"
AshokTewatia-2318 answered

I am facing exact problem.

var list = _featureManager.GetFeatureNamesAsync(); // list is null


var toggle2 = _featureManager.IsEnabledAsync("toggle2"); // it give me my value.

Why GetFeatureNamesAsync is returning null? Any Clues?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AmrElgarhy avatar image
0 Votes"
AmrElgarhy answered

To start seeing the features list you will need to iterate through, something like that:
var featureNames = _featureManager.GetFeatureNamesAsync();

         await foreach (var name in featureNames)
         {
             var isEnabled = await _featureManager.IsEnabledAsync(name);
             featureList.Add(new FeatureFlag()
             {
                 FeatureName = name,
                 IsEnabled = isEnabled
             });
         }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.