.net - System.TypeLoadException:从负载测试插件使用 KeyVault 时的“方法 'get_SerializationSettings'
问题描述
我有一个Key Vault
用于预先验证 Web 请求的负载测试。一旦代码尝试调用KeyVaultClient
内部使用类的方法,就会抛出以下异常:
System.TypeLoadException:来自程序集“Microsoft.Azure.KeyVault,版本=3.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”的“Microsoft.Azure.KeyVault.KeyVaultClient”类型中的“方法“get_SerializationSettings”没有实现。
我试图将 KeyVault nuget 降级到 version 2.0.6
,但我收到相同的错误,版本为 2.0.0.0。
我正在使用 .NET 框架 4.7.2 和 Visual Studio 2017 v.15.9.7
更新:当 nuget Microsoft.Rest.ClientRuntime nuget(由 Microsoft.Azure.KeyVault 引用)更新到版本 2.3.20 时,会出现此问题。如果我将其回滚到 v. 2.3.18,负载测试工作正常。
解决方案
这是我在使用 3.0.3 库访问 keyvault 客户端时在我的代码中使用的东西,它对我有用。在下面试试这个,看看它是否有效。
Uri ADL_TOKEN_AUDIENCE = new Uri(urlAudience);
var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
public static async Task<string> GetAccessToken(string azureTenantId, string azureAppId, string azureSecretKey)
{
var context = new AuthenticationContext(ConfigurationManager.AppSettings.Get("Authority") + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, secretKey);
var tokenResponse = await context.AcquireTokenAsync(ConfigurationManager.AppSettings.Get("VaultUrl"), clientCredential);
var accessToken = tokenResponse.AccessToken;
return accessToken;
}
尝试以这种方式获取令牌,它应该可以工作。
推荐阅读
- c++ - C++ 函数输出在返回后发生变化
- java - Java:如果输入“Y”,则对话框卡在循环中,但如果输入“N”则不会
- c - 我为 Jacobi 迭代方法编写了这个 C 程序,但是我得到 Nan 和 infinity 作为输出,我尝试从
- c# - 如何在 Entity Framework Core 中定义一个共享实体并使其他实体与它具有一对多的关系?
- oracle - 如何在 oracle 中转换字符串格式,例如从 8 月 17 日至今
- python - 如何在 Python 中显示线性回归的三阶多项式边界线?
- graphql - 如何使用 graphql-js 类(无 SDL)扩展现有类型?
- c# - 使用列表视图时 UWP 中的 ToolTipService 崩溃
- python - 使用来自 slim 的预训练模型训练 ssd inception_v3
- javascript - 如何在 javascript 中打印 php 变量并更改 php 的数组格式