Could not load file or assembly when Integrating Azure Key Vault

0

I am trying to integrate Azure Keyvault to a web API. Here's the code from a Microsoft Doc:

  var builtConfig = config.Build();
                    using (var store = new X509Store(StoreLocation.CurrentUser))
                    {
                        store.Open(OpenFlags.ReadOnly);
                        var certs = store.Certificates
                            .Find(X509FindType.FindByThumbprint,
                                builtConfig["AzureKeyVault:CertThumbprint"], false);

                        config.AddAzureKeyVault(
                            $"https://{builtConfig["AzureKeyVault:Vault"]}.vault.azure.net/",
                            builtConfig["AzureKeyVault:ClientId"],
                            certs.OfType<X509Certificate2>().Single());

                        store.Close();
                    }

However, I got an error saying:

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Source=Microsoft.Extensions.Configuration.AzureKeyVault

Here's the StackTrace:

at Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions.d__5.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Extensions.Configuration.AzureKeyVaultConfigurationExtensions.GetTokenFromClientCertificate(String authority, String resource, String clientId, X509Certificate2 certificate) at Microsoft.Azure.KeyVault.KeyVaultCredential.d__9.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.KeyVault.KeyVaultCredential.d__10.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.KeyVault.KeyVaultClient.d__66.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.KeyVault.KeyVaultClientExtensions.d__49.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationProvider.d__5.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Extensions.Configuration.AzureKeyVault.AzureKeyVaultConfigurationProvider.Load() at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors) at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()

Does anyone know what's the reason?

c#
security
asp.net-core
azure-keyvault
x509certificate2
asked on Stack Overflow Jun 12, 2020 by superninja

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0