[英]System.TypeLoadException: 'Method 'get_SerializationSettings' when using KeyVault from Load Test Plugin
I have a load test that uses Key Vault
to pre-authenticate web requests.我有一个负载测试,它使用Key Vault
对 Web 请求进行预身份验证。 As soon as the code tries to call the method that uses KeyVaultClient
class inside, the following exception throws:一旦代码尝试调用内部使用KeyVaultClient
类的方法, 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. System.TypeLoadException: 程序集“Microsoft.Azure.KeyVault.KeyVaultClient”中类型“Microsoft.Azure.KeyVault.KeyVaultClient”中的“方法”get_SerializationSettings,来自程序集“Microsoft.Azure.KeyVault,版本=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”没有实现。
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.我试图将 KeyVault nuget 降级到版本2.0.6
,但我收到相同的错误,版本为 2.0.0.0。
I am using .NET framework 4.7.2 and Visual Studio 2017 v.15.9.7我正在使用 .NET 框架 4.7.2 和 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.更新:当 nuget Microsoft.Rest.ClientRuntime nuget(由 Microsoft.Azure.KeyVault 引用)更新到版本 2.3.20 时,会出现此问题。 If I roll it back to v. 2.3.18, the load test works fine.如果我将它回滚到 v. 2.3.18,负载测试工作正常。
Here is something i used it in my code while accesing keyvault client using 3.0.3 library and it worked for me.这是我在使用 3.0.3 库访问 keyvault 客户端时在我的代码中使用它的东西,它对我有用。 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.尝试以这种方式获取令牌,它应该可以工作。
The problem is that the load test uses the app.config from the host process "QTAgent_40.exe":问题是负载测试使用了来自主机进程“QTAgent_40.exe”的 app.config:
C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\QTAgent_40.exe.config 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). Newtonsoft.Json - dll 从文件夹“C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\PrivateAssemblies”(版本 9.0)加载。 But Microsoft.Rest.ClientRuntime 2.3.19 (and higher) requires Newtonsoft.Json 10.0.但 Microsoft.Rest.ClientRuntime 2.3.19(及更高版本)需要 Newtonsoft.Json 10.0。
Solution:解决方案:
C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\QTAgent_40.exe.config 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.