Unable to fetch the azure key Vault secret in .net sharepoint application

M R, MEGHA 0 Reputation points

Whenever I am trying to retrieve the azure key vault secret in .net sharepoint application, I am getting the below exception for the below mentioned code . Tried to update all the nugget packages with the expected version but, still unable to troubleshoot the error.

if (!string.IsNullOrEmpty(KeyVaultName) && !string.IsNullOrEmpty(KeyVaultSecret) && !string.IsNullOrEmpty(ManagedIdentityClientId))
    var kvUri = $"https://{KeyVaultName}.vault.azure.net";

    var options = new DefaultAzureCredentialOptions()
        ManagedIdentityClientId = ManagedIdentityClientId
    var credential = new DefaultAzureCredential(options);

    var client = new SecretClient(new Uri(kvUri), credential);
    var secret = client.GetSecret(KeyVaultSecret);
   string accountPassword = secret.Value.Value;


Below is the exception:
  Message=Could not load file or assembly 'Azure.Identity, Version=, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
   at ACNAdHocProjectBackup.ACNPSIConfigurator.SetExternalConfigurationData() in D:\MeghaMR\Tools_MSPS2019_ACNAdHocProjectBackup\ACNAdHocProjectBackup\ACNPSIConfigurator.cs:line 453
   at ACNAdHocProjectBackup.ACNPSIConfigurator.ConfigurePSIClients() in D:\MeghaMR\Tools_MSPS2019_ACNAdHocProjectBackup\ACNAdHocProjectBackup\ACNPSIConfigurator.cs:line 102
   at ACNAdHocProjectBackup.Layouts.ACNAdHocProjectBackup.AdHocProjectBackup.configurePSI() in D:\MeghaMR\Tools_MSPS2019_ACNAdHocProjectBackup\ACNAdHocProjectBackup\Layouts\ACNAdHocProjectBackup\AdHocProjectBackup.aspx.cs:line 183
   at ACNAdHocProjectBackup.Layouts.ACNAdHocProjectBackup.AdHocProjectBackup.Page_Load(Object sender, EventArgs e) in D:\MeghaMR\Tools_MSPS2019_ACNAdHocProjectBackup\ACNAdHocProjectBackup\Layouts\ACNAdHocProjectBackup\AdHocProjectBackup.aspx.cs:line 39

  This exception was originally thrown at this call stack:
    ACNAdHocProjectBackup.ACNPSIConfigurator.ConfigurePSIClients() in ACNPSIConfigurator.cs
    ACNAdHocProjectBackup.Layouts.ACNAdHocProjectBackup.AdHocProjectBackup.configurePSI() in AdHocProjectBackup.aspx.cs
    ACNAdHocProjectBackup.Layouts.ACNAdHocProjectBackup.AdHocProjectBackup.Page_Load(object, System.EventArgs) in AdHocProjectBackup.aspx.cs
SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,243 questions
Microsoft Technologies based on the .NET software framework.
3,438 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,793 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,354 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,081 Reputation points Microsoft Vendor

    Hi @M R, MEGHA,

    According the error message, it seems you haven't added Azure Identity client library. You could refer to the following command to install the library azure key Vault secret needed.

    dotnet add package Azure.Security.KeyVault.Secrets
    dotnet add package Azure.Identity

    Here is the document for more details of the steps


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.