The type initializer for "Azure.Core.Pipeline.HttpClientTransport" threw an exception.'

0

I am getting below exception when trying to access the azure key vault.

The type initializer for "Azure.Core.Pipeline.HttpClientTransport" threw an exception.' FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)

Below is my code: When trying to create the secretclient object, it is throwing that exception:

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

        var value1= secretClient.GetSecret("Key1");
        var value2= secretClient.GetSecret("Key2");
        var result = new Dictionary<string, string>
        {
            {value1.Value.Value, value2.Value.Value}
        };

Appreciate the help.

c#
asp.net
azure
azure-web-app-service
azure-keyvault
asked on Stack Overflow May 12, 2020 by Sachin

1 Answer

0

I have tested your code on my side, it works fine. Please check the values of tenantId, clientId and clientSecret. Also, you can check if you are using the correct dependencies. Here is my whole code for your reference.

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using System;
using System.Collections.Generic;
using System.Text;

namespace TonyTestGraph
{
    class KeyValutTest
    {
        static void Main(string[] args)
        {
            SecretClient secretClient = new SecretClient(
               new Uri("https://tonykeyvault.vault.azure.net/"),
              new ClientSecretCredential("xxx.onmicrosoft.com", "366b3XXX113-4d73-ac2b-cfe920b3a6ae", "HMeQ41RWacxuFgxxx02Ce43qb.1.K-~S")
           );

                var value1 = secretClient.GetSecret("connectionString");
            Console.WriteLine(value1);
        }
    }
}

enter image description here

Package version:

Azure.Identity 1.2.0-preview.3

Azure.Security.KeyVault.Secrets 4.0.3

answered on Stack Overflow May 14, 2020 by Tony Ju

User contributions licensed under CC BY-SA 3.0