App Configuration ConnectionString null .Net7 Function App

MatheusNani 6 Reputation points
2023-03-24T17:15:49.01+00:00

Hey guys. I have an issue with App Configuration + Function App v4 + .NET7 dotnet-isolated.
I'm trying to connect my function to App Configuration but I'm getting weird behaviors.

Execute: dotnet user-secrets set ConnectionStrings:AzureAppConfigEndpoint "<AppConfigEndpoint>"

Program.cs
User's image

I don't get this error locally, when I deploy it to Azure, I get the error: User's image

Or

This is from Microsoft Docs.
https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-azure-functions-csharp?tabs=isolated-process
User's image

I get this:

User's image

This is the App Settings value not App Configuration value.

To make this work and get the correct value from App Configuration I did this:
I'm looking for the value in test1 variable.
Not sure why test0 is retrieving "Development" - I didn't set that value anywhere.
User's image

Am I missing something or doing something wrong?
I would like to understand It better.

Thank you!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,394 questions
Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
210 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,236 Reputation points
    2023-04-03T13:15:40.2933333+00:00

    MatheusNani Thank you for posting your question in Microsoft Q&A. Based on my understanding, you are referring to code snippet in doc: Connect to an App Configuration store and added AddAzureAppConfiguration in ConfigureAppConfiguration section.

    However, you need to add AddAzureAppConfiguration to ConfigureServices so that this service is available through dependency injection. I assume, you are reading AppConfiguration values in your function code and here is the full code sample for your reference.

    Reference snippet for reading AppConfiguration: (https://github.com/Azure/AppConfiguration/blob/main/examples/DotNetCore/AzureFunction/FunctionAppIsolatedMode/ShowMessage.cs)

    public class ShowMessage
        {
            private readonly IConfiguration _configuration;
            private readonly ILogger _logger;
    
            public ShowMessage(IConfiguration configuration, ILoggerFactory loggerFactory)
            {
                _configuration = configuration;
                _logger = loggerFactory.CreateLogger<ShowMessage>();
            }
    
            [Function("ShowMessage")]
            public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
            {
                _logger.LogInformation("C# HTTP trigger function processed a request.");
    
                var response = req.CreateResponse(HttpStatusCode.OK);
                response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
    
                // Read configuration data
                string key = "TestApp:Settings:Message";
                string message = _configuration[key];
    
                response.WriteString(message ?? $"Please create a key-value with the key '{key}' in Azure App Configuration.");
    
                return response;
            }
        }
    

    If you face any issues following the code sample, share the full code snippet of how you read values in your function code. For second part, you are actually reading app settings of AZURE_FUNCTIONS_ENVIRONMENT and it returns as expected (doc reference: AZURE_FUNCTIONS_ENVIRONMENT).

    I hope this helps with your question and let me know for any other questions.

    0 comments No comments