c# - 集成 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()
有谁知道是什么原因?
解决方案
推荐阅读
- eclipse - 如何在调试期间在 FreeRTOS 任务列表中显示运行时
- javascript - 数字为 0 的 Ajax 响应被解析为未定义
- c# - XSD 验证错误 - 缺少有关 xsd 架构错误代码的详细信息
- python - 查找每类 TF-IDF 得分最高的前 n 个术语
- android - 获取,失败 [INSTALL_FAILED_OLDER_SDK:installPackageLI 期间解析失败
- java - Javafx 无法加载新添加的图像
- php - 如何使用 ajax 将 json 数据发送到 php 文件
- python - Django Forms - 验证错误显示两次
- kotlin - 控制器接收具有空字段的对象
- azure - 无法从 Microsoft Graph API 获取邮件