英文:
How can I resolve 'Value cannot be null. (Parameter 'Version')' error while updating Azure Key Vault's secret expiration date in dotnet code?
问题
I'm trying to update the expiration date of the secret in Azure Key Vault from my .NET code. However, I'm getting an error when calling the method UpdateSecretPropertiesAsync()
. Here is some related code:
var credential = new ClientSecretCredential(_configuration[Constants.AZURE_TENANT_ID], _configuration[Constants.AZURE_CLIENT_ID], _configuration[Constants.AZURE_CLIENT_SECRET]);
var client = new SecretClient(new Uri(_configuration[Constants.KEY_VAULT_URL_UAT]), credential);
var secretProperties = new SecretProperties(secretName);
secretProperties.ExpiresOn = DateTimeOffset.Now.AddYears(2);
client.UpdateSecretProperties(secretProperties); // Here, I'm getting the error (Value cannot be null. (Parameter 'Version'))
This is the documentation related to UpdateSecretPropertiesAsync
: link
Can anyone please help me with this as I have very strict timelines?
Even though I tried to add secretProperties.Version
, Version is a read-only field. I'm expecting this line of code to work, but for some reason, it is throwing the error. No idea why it is.
英文:
Im trying to update the expiration date of the secret in Azure key vault from my dotnet code.
But Im getting this error on this calling method: UpdateSecretPropertiesAsync().
Here is some related part of code:
var credential = new ClientSecretCredential(_configuration[Constants.AZURE_TENANT_ID], _configuration[Constants.AZURE_CLIENT_ID], _configuration[Constants.AZURE_CLIENT_SECRET]);
var client = new SecretClient(new Uri(_configuration[Constants.KEY_VAULT_URL_UAT]), credential);
var secretProperties = new SecretProperties(secretName);
secretProperties.ExpiresOn = DateTimeOffset.Now.AddYears(2);
client.UpdateSecretProperties(secretProperties); // here im getting the error(Value cannot be null. (Parameter 'Version'))
This is the documentation related to UpdateSecretPropertiesAsync: link
Can anyone please help me with this as I have very strict timelines.
Even though I tried to add
secretProperties.Version
but Version is readonly field.
Im Expecting this line of code to work but for some reason it is throwing the error. No idea why it is.
答案1
得分: 6
更新秘密的属性时,实际上是在更新秘密的特定版本,而不是整个秘密。
因此,不要使用以下方式:
var secretProperties = new SecretProperties(secretName);
尝试获取现有版本:
KeyVaultSecret secretVersion = client.GetSecret(secretName);
var secretProperties = secretVersion.Properties;
英文:
When updating a secret's properties, you're actually updating a specific version of the secret, not the secret as a whole.
So instead of
var secretProperties = new SecretProperties(secretName);
try fetch existing
KeyVaultSecret secretVersion = client.GetSecret(secretName);
var secretProperties = secretVersion.Properties;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论