0

I am trying to read the values from Azure Key vault using below code, but it always throws below exception at first time and second time it just runs fine. As it is System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.' No way to handle it(at least I am aware).

My code looks like:

private Dictionary<string, string> GetCredentials()
    {

        string tenantId =  "<TenantId>";
        string clientId = "<ClientId>";
        string clientSecret = "<ClientSecret>";
        string vaultUrl ="<VaultUrl>";

        SecretClient secretClient = new SecretClient(
            new Uri(vaultUrl), 
           new ClientSecretCredential(tenantId, clientId, clientSecret)
        );

        var UserName = secretClient.GetSecret("UserName");
        var Password = secretClient.GetSecret("Password");
        var result = new Dictionary<string, string>
        {
            {UserName.Value.Value, Password.Value.Value}
        };
        return result;
    }
Sachin
  • 459
  • 1
  • 7
  • 22

1 Answers1

0

We cannot exactly say that this exception is thrown while accessing the azure key vault. Because, System.ExecutionEngineException is thrown when there is an issue in CLR. might be an error that happen before. The only solution i see is to refactor your code from the starting point to this point(where you access key vault). You can have an in-depth understanding about the issue over here

Lasanga Guruge
  • 832
  • 1
  • 5
  • 15
  • It is coming exactly at this line : SecretClient secretClient = new SecretClient( new Uri(vaultUrl), new ClientSecretCredential(tenantId, clientId, clientSecret) ); – Sachin May 04 '20 at 18:07