首页 > 解决方案 > 集成 Azure Key Vault 时无法加载文件或程序集

问题描述

我正在尝试将 Azure Keyvault 集成到 Web API。这是来自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();
                    }

但是,我收到一条错误消息:

System.IO.FileNotFoundException HResult=0x80070002 Message=无法加载文件或程序集“Microsoft.IdentityModel.Clients.ActiveDirectory.Platform,版本=3.14.2.11,文化=中性,PublicKeyToken=31bf3856ad364e35”。该系统找不到指定的文件。
源=Microsoft.Extensions.Configuration.AzureKeyVault

这是堆栈跟踪:

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

有谁知道是什么原因?

标签: c#securityasp.net-coreazure-keyvaultx509certificate2

解决方案


推荐阅读