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

Mac(M1)上VS Code使用Azure Key Vault遇认证错误求助

M1芯片MacBook的VS Code中运行C#控制台应用访问Azure Key Vault报错问题

我按照官方指南在C#控制台应用中读写Azure Key Vault的密钥,该操作在Windows机器上可正常执行,但在M1芯片的MacBook上通过VS Code运行时出现以下错误:

Unhandled exception. Azure.Identity.CredentialUnavailableException: DefaultAzureCredential failed to retrieve a token from the included credentials. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/defaultazurecredential/troubleshoot
- EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot
- ManagedIdentityCredential authentication unavailable. Multiple attempts failed to obtain a token from the managed identity endpoint.
- Operating system Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101 isn't supported.
- Stored credentials not found. Need to authenticate user in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot
- Azure CLI not installed
- PowerShell is not installed.

我已安装AZ CLI工具并执行了az login(验证可用),甚至能通过CLI列出密钥库,网络连接正常。

更新:仅在VS Code中运行时出现该错误,切换到Visual Studio即可正常工作。

最小代码示例:

Console.WriteLine("Attempting to read from Key Vault...");

string keyVaultName = "<key-vault-name>";

var kvUri = "https://" + keyVaultName + ".vault.azure.net";
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());

string secretName = "<secret-name>";
var secret = await client.GetSecretAsync(secretName);

Console.WriteLine(secret.Value.ToString());

内容的提问来源于stack exchange,提问作者Jakob Busk Sørensen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 01:50:24