john paz
john paz

Reputation: 328

Azure Key Vault Connected Service to ASP.NET 4.7.1: CompilationLock exception

We're trying to move our application secrets into Azure Key Vault, so I've upgraded our ASP.NET Web app project to 4.7.1 and followed the steps to add Key Vault as a connected service, using my Visual Studio Enterprise subscription to create the Vault. I'm logged into my account with the subscription in VS, and the "Add Connected Service" functionality was successful, I've added the configuration sections in the web.config, as explained in the linked documentation:

  <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="MyVaultName"
        type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=1.0.0.0, Culture=neutral"
        vaultUri="https://MyVaultName.vault.azure.net/" />
    </builders>
  </configBuilders>

However, the moment I add the configBuilders="AzureKeyVault" attribute to the appSettings tag and build, I receive a

The type initializer for 'System.Web.Compilation.CompilationLock' threw an exception.

I'm pretty new (okay, complete noob) with ConfigBuilder functionality, so I presume I'm missing something simple. I seem to also have replicated the final solution for this question, with no joy.

What am I missing? tia

Upvotes: 1

Views: 344

Answers (1)

Joey Cai
Joey Cai

Reputation: 20067

I follow the tutorial and it works fine in my site.

It may caused by your upgrade of .net framework.

Try to re-install of .NET and clean the project then restart Visual Studio to fix the issue.

Upvotes: 1

Related Questions