9

I have a load test that uses Key Vault to pre-authenticate web requests. As soon as the code tries to call the method that uses KeyVaultClient class inside, the following exception throws:

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.

Dmitry Pro
  • 91
  • 1
  • 4

2 Answers2

0

Here is something i used it in my code while accesing keyvault client using 3.0.3 library and it worked for me. try this below and see if it works.

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;
}

Try to get the token in this way, it should work.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • This does not work. The exception appears on entering the method that uses KeyVaultClient class. Seems that it happens during the JIT compilation of some static methods in this class. – Dmitry Pro Feb 28 '19 at 17:44
0

The problem is that the load test uses the app.config from the host process "QTAgent_40.exe":

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\QTAgent_40.exe.config

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
    <bindingRedirect oldVersion="4.5.0.0-9.0.0.0" newVersion="9.0.0.0"/>
</dependentAssembly>

The Newtonsoft.Json - dll is loaded from the folder "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PrivateAssemblies" (Version 9.0). But Microsoft.Rest.ClientRuntime 2.3.19 (and higher) requires Newtonsoft.Json 10.0.

Solution:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\QTAgent_40.exe.config

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
    <bindingRedirect oldVersion="4.5.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
Eichi
  • 178
  • 3
  • 8