azure函数defaustazurecrecrecrecrecreCredential方法找不到azure.core.tokenrequestcontext

发布于 2025-01-26 06:24:10 字数 1067 浏览 4 评论 0原文

我正在尝试从Azure函数c#脚本中的Azure密钥库中读取秘密,但是我面临的错误

我已经创建了一个function.proj文件,其中有下面的内容,

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Azure.Identity" Version="1.6.0" />       
        <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.3.0" />
    </ItemGroup>    
</Project>

我启用了从我的功能应用程序创建了一个对象ID号。 选择秘密权限的获取和列表

然后复制此数字,并将其添加到我的密钥保险库访问策略中,然后在我尝试以下代码时

string keyVaultUri = "https://my-vault-test.vault.azure.net/";
var client = new SecretClient(new Uri(keyVaultUri), new DefaultAzureCredential());
var secret = client.GetSecret("first-secret");

:错误:

2022-05-04T16:41:51.383 [错误]执行'functions.myfff'(失败, id =数字...,持续时间= 574ms)未找到方法:'void azure.core.core.tokenrequestcontext..ctor(system.String [],System.String, System.String,System.String)'。

I'm trying to read secrets from a Azure Key Vault in my azure function c# script, but I'm facing an error

I already create a function.proj file with content below

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Azure.Identity" Version="1.6.0" />       
        <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.3.0" />
    </ItemGroup>    
</Project>

I enabled the System assigned from my Function App and it created a Object Id number.
Then copied this number and added it to my Key Vault Access policies at Select principal option and choose Get and List for Secret Permissions

When I try this code below:

string keyVaultUri = "https://my-vault-test.vault.azure.net/";
var client = new SecretClient(new Uri(keyVaultUri), new DefaultAzureCredential());
var secret = client.GetSecret("first-secret");

error:

2022-05-04T16:41:51.383 [Error] Executed 'Functions.myFff' (Failed,
Id=number..., Duration=574ms) Method not found: 'Void
Azure.Core.TokenRequestContext..ctor(System.String[], System.String,
System.String, System.String)'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲喜皆因你 2025-02-02 06:24:10

我更改了包装的版本,它运行良好...

1.5.0 for Azure.Identity

4.2.0 for Azure.security.keyvault.secrets

I changed the versions of the packages and it worked well...

1.5.0 for Azure.Identity

4.2.0 for Azure.Security.KeyVault.Secrets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文