You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Framework 4.7.2中Azure Key Vault版本不兼容错误求助

解决Azure Key Vault SDK版本不兼容问题

问题分析

The specified version (7.5) is not recognized. Consider using the latest supported version (7.1)

这个错误源于你使用的Azure.Security.KeyVault.Secrets和Azure.Identity SDK版本过高,Azure Stack Hub仅支持到API版本7.1,而新版SDK默认调用了更高的7.5版本,且SecretClientOptions的Version属性为只读,无法直接修改。

解决方案

1. 降级NuGet包到兼容版本

Azure Stack Hub对Azure SDK有严格的版本适配要求,需安装匹配的包版本:

  • 卸载当前的Azure.Security.KeyVault.Secrets和Azure.Identity包
  • 安装以下兼容版本:
    • Azure.Security.KeyVault.Secrets 4.2.0
    • Azure.Identity 1.3.0
      这两个版本默认使用API版本7.1,完全适配Azure Stack Hub的要求。

2. 优化代码配置

调整代码以适配Azure Stack Hub环境,同时修正原代码中的硬编码和返回值问题:

using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using System;

namespace KeyVaultNS
{
    public class KeyVault
    {
        public static string GetSecrets(string keyVaultURL, string secretKey)
        {
            var kvUri = new Uri(keyVaultURL);
            var options = new SecretClientOptions() 
            { 
                DisableChallengeResourceVerification = true,
                // 指定Azure Stack Hub的Key Vault受众
                Audience = "https://vault.azurestack.local"
            };
            var client = new SecretClient(kvUri, new DefaultAzureCredential(), options);
            // 获取实际密钥值,而非类型字符串
            var secret = client.GetSecret(secretKey).Value;
            return secret.Value;
        }
    }
}

3. 确认基础配置

再次核对环境变量AZURE_CLIENT_ID、AZURE_CLIENT_SECRET、AZURE_TENANT_ID的正确性,同时确保服务主体在Azure Stack Hub的Key Vault中已被授予机密读取权限。

内容的提问来源于stack exchange,提问作者Michigan Lou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 19:32:11