System.TypeLoadException:从负载测试插件使用KeyVault时,方法“ get_SerializationSettings”

Dmi*_*Pro 8 .net load-testing azure azure-keyvault visual-studio-2017

我有一个Key Vault用于预先验证Web请求的负载测试。一旦代码尝试调用KeyVaultClient内部使用类的方法,就会引发以下异常:

System.TypeLoadException: 'Method 'get_SerializationSettings' in type 'Microsoft.Azure.KeyVault.KeyVaultClient' from assembly 'Microsoft.Azure.KeyVault, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.

I have tried to downgrade the KeyVault nuget to the version 2.0.6, but I receive the same error, with version 2.0.0.0.

I am using .NET framework 4.7.2 and Visual Studio 2017 v.15.9.7

UPDATE: The issue appears when the nuget Microsoft.Rest.ClientRuntime nuget (referenced by Microsoft.Azure.KeyVault) is updated to version 2.3.20. If I roll it back to v. 2.3.18, the load test works fine.

Moh*_*rma 0

这是我在使用 3.0.3 库访问 keyvault 客户端时在代码中使用的东西,它对我有用。尝试下面的方法,看看是否有效。

Uri ADL_TOKEN_AUDIENCE = new Uri(urlAudience);
var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)

尝试以这种方式获取令牌,它应该可以工作。