question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't set secret and its value using Azure.Security.KeyVault.Secrets SDK

See original GitHub issue

I’m using Azure.Security.KeyVault.Secrets v4.3.0 and the method SetSecretAsync of SecretClient. It’s failing with following error:

System.TypeInitializationException: "The type initializer for 'Azure.Security.KeyVault.Secrets.KeyVaultSecret' threw an exception." ---> System.IO.FileNotFoundException: "Could not load file or assembly 'System.Text.Encodings.Web, Version=4.0.5.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.\n"
  --- End of inner exception stack trace ---
  at at Azure.Security.KeyVault.Secrets.KeyVaultSecret.WriteProperties(Utf8JsonWriter json)

I’m using Visual Studio Community 2019 for Mac, Version 8.10.22 (build 11). The project is Azure Functions application. I’m debugging it locally using Azure Functions tools. I cleared up the NuGet cache, removed all stalled System.Text.Encodings.Web assemblies on my Mac.

Here is the list of references across 4 different projects within the solution that reference each other:

project 1:
<ItemGroup>
    <PackageReference Include="Azure.Core" Version="1.24.0" />
    <PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.3.0" />
    <PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.3.0" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.3.0" />
    <PackageReference Include="FluentValidation" Version="10.4.0" />
    <PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="10.4.0" />
    <PackageReference Include="Microsoft.FeatureManagement" Version="2.5.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.24" />
    <PackageReference Include="Azure.ResourceManager.KeyVault" Version="1.0.0-beta.6" />
    <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
    <PackageReference Include="AutoMapper" Version="10.1.1" />
  </ItemGroup>

project 2:
<ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.23" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.13" />
    <PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="2.4.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.1.0" />
  </ItemGroup>

project 3:
<ItemGroup>
    <PackageReference Include="Azure.Data.Tables" Version="12.5.0" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.9.0" />
  </ItemGroup>

project 4:
<ItemGroup>
    <PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.38.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.20" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.20" />
    <PackageReference Include="Azure.Identity" Version="1.6.0" />
    <PackageReference Include="Azure.ResourceManager" Version="1.0.0-beta.8" />
  </ItemGroup>

Project 4 from the list above has the code that is failing. It references project 1. Project 1 references project 3. Project 2 (main project) references project 4 and project 1.

Looks like some package is messing everything up or this is the bug in Azure.Security.KeyVault.Secrets. Do you have any guidance about Azure SDK on which versions of mentioned packages can be used together?

Thanks in advance.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alex-zarcommented, Jul 21, 2023

yeah, this was more than a year ago 😃 I bet we already migrated to a newer .NET version and newer runtime since then. I haven’t heard about such issues tbh. Let’s consider this as addressed. I will reach out if it is not.

1reaction
heathscommented, Jul 20, 2023

Sorry, but this seems to have slipped through the cracks. Was this still a problem? Dependencies across the Azure Functions runtime, PowerShell support, etc., have all since been updated so I’m hopeful this is no longer a problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Key Vault secret client library for .NET
The Azure Key Vault secrets client library allows you to securely store and control the access to tokens, passwords, API keys, and other...
Read more >
Set and retrieve a secret from Key Vault using Azure portal
Navigate to your new key vault in the Azure portal · On the Key Vault settings pages, select Secrets. · Select on Generate/Import....
Read more >
Set Secret - REST API (Azure Key Vault)
The SET operation adds a secret to the Azure Key Vault. ... The value you provide may be copied globally for the purpose...
Read more >
How to set tags for Secret in Azure Key Vault using C# - ...
Unfortunately, the Azure.Security.KeyVault.Secrets library does not provide a built-in method to set tags for secrets directly.
Read more >
Azure Key Vault secret client library for .NET
The secret client library allows you to securely store and control the access to tokens, passwords, API keys, and other secrets. This library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found