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:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Azure.Identity, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
Source=ACNAdHocProjectBackup
StackTrace:
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