1

I am trying to access App configuration with a simple console app. So far I have:

static void Main(string[] args)
{
    IConfiguration config = new ConfigurationBuilder()
              .AddUserSecrets("e7315677-d6aa-41ab-b7cc-8e801a7c8ae9")
              .AddAzureAppConfiguration("ConnectionStrings:AppConfig")
              .Build();
    Console.WriteLine("Hello World!");
}

But an exception is thrown indicating that

System.ArgumentException: 'Connection string doesn't have value for keyword 'ConnectionStrings:AppConfig'.'

I have put this connection string in secrets.json and I know that it is valid. What am I doing wrong?

{
  "ConnectionStrings:AppConfig": "<my connection string>"
}

Thank you.

Kevin

Kevin Burton
  • 2,032
  • 4
  • 26
  • 43

3 Answers3

9

Make sure the connection string begins with "Endpoint=". It's looking for key/value pairs, and interprets a value without a key as a key without a value.

Jim Cargle
  • 91
  • 1
  • 2
4

The AddAzureAppConfiguration method expects a connection string as an argument. You receive System.ArgumentException since "ConnectionStrings:AppConfig" is not a valid connection string.

In order to use the connection string defined in the user secrets to initialize the Azure App Configuration provider, we can first build an IConfiguration instance with the user secret and use it to access the connection string property. Here's a modified version of your code that works.

static void Main(string[] args)
{
    IConfiguration intermediate = new ConfigurationBuilder()
        .AddUserSecrets("e7315677-d6aa-41ab-b7cc-8e801a7c8ae9")
        .Build();

    IConfiguration configuration = new ConfigurationBuilder()
        .AddAzureAppConfiguration(intermediate["ConnectionStrings:AppConfig"])
        .Build();
}

Abhilash Arora
  • 277
  • 2
  • 4
1

Don't make the same mistake I did and copy the endpoint from the Azure App Service portal. Look for the primary key section and there is a copy button there for the connection string. It should then give you aa string that includes that starts Endpoint= and includes the id and secret

pwilcox83
  • 51
  • 7