簡體   English   中英

System.TypeLoadException:從負載測試插件使用 KeyVault 時的“方法 'get_SerializationSettings'

[英]System.TypeLoadException: 'Method 'get_SerializationSettings' when using KeyVault from Load Test Plugin

我有一個負載測試,它使用Key Vault對 Web 請求進行預身份驗證。 一旦代碼嘗試調用內部使用KeyVaultClient類的方法, KeyVaultClient拋出以下異常:

System.TypeLoadException: 程序集“Microsoft.Azure.KeyVault.KeyVaultClient”中類型“Microsoft.Azure.KeyVault.KeyVaultClient”中的“方法”get_SerializationSettings,來自程序集“Microsoft.Azure.KeyVault,版本=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”沒有實現。

我試圖將 KeyVault nuget 降級到版本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;
}

嘗試以這種方式獲取令牌,它應該可以工作。

問題是負載測試使用了來自主機進程“QTAgent_40.exe”的 app.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>

Newtonsoft.Json - dll 從文件夾“C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\PrivateAssemblies”(版本 9.0)加載。 但 Microsoft.Rest.ClientRuntime 2.3.19(及更高版本)需要 Newtonsoft.Json 10.0。

解決方案:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM