Poor performance with key vault access from configuration builders when retrieving both app settings and connection strings

We are looking to move sensitive configuration settings for a legacy .net framework 4.8 application to be held in Azure Key Vault which we have used successfuly for .net 6, 7, and 8 for a while now.

Using the NuGet package Microsoft.Configuration.ConfigurationBuilders.Azure and retrieving the configuration settings from ConfigurationManager.AppSettings works fine, adding a subsequent retrieval from ConfigurationManager.ConnectingStrings can take about 30 seconds to retrieve the connection string

This was a new vanilla console application using .net framework 4.8. Added the NugGet package Microsoft.Configuration.ConfigurationBuilders.Azure (current version 3.0.0). I’ve upgraded all the related packages to use latest versions as some were marked as deprecated. I’ve signed in to Azure using the Azure Service Authentication option within Visual Studio 2022.

I have set up a couple of secrets in Key Vault named Test2 and MyConnection.

My App.config has the following related sections:

<configSections>
  <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>

<configBuilders>
  <builders>
    <add name="AzureKeyVault" vaultName="Some-KeyVault" type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  </builders>
</configBuilders>

<connectionStrings configBuilders="AzureKeyVault">
  <add name="MyConnection" connectionString="Obtained from key vault" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings configBuilders="AzureKeyVault">
  <add key="Test1" value="Test value 1" />
  <add key="Test2" value="Should come from key vault" />
</appSettings>

The console app then uses those settings – I have added a stop watch to show the issue:

static void Main(string[] args)
{
    Console.WriteLine("Reading configuration file");

    Stopwatch watch = new Stopwatch();
    watch.Start();

    Console.WriteLine($"Test1 --> {ConfigurationManager.AppSettings["Test1"]}");
    Console.WriteLine($"Test 1 completed after {watch.Elapsed}");

    Console.WriteLine($"Test2 --> {ConfigurationManager.AppSettings["Test2"]}");
    Console.WriteLine($"Test 2 completed after {watch.Elapsed}");

    Console.WriteLine($"ConnectionString -->{ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString}");
    Console.WriteLine($"Test 3 completed after {watch.Elapsed}");
}

If I run this application I get:

Reading configuration file
Test1 --> Test value 1
Test 1 completed after 00:00:03.8970375
Test2 --> Test 2 coming from key vault
Test 2 completed after 00:00:03.8972798
ConnectionString --> Server=(local);Database=SomeDatabase;User ID=SomeUser;password=SomePassword;
Test 3 completed after 00:00:34.2944765

So it took over 30 seconds to retrieve and output the connection string. Strangely if I change the order and retrieve the connection string first and then the app settings, the connection string is reasonably quick but the app settings takes around 30 seconds.

We know therefore that we can connect to key vault reasonable quickly and retrieve a setting. It is that reading from a 2nd section that causes a delay.

Can anyone shed some light on why this happens?

New contributor

Geoff Lloyd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật