azure-sdk-for-net: SetSecretAsync gives error "Could not load file or assembly 'System.Text.Encodings.Web"

Describe the bug

When I call SetSecretAsync() method, I’m having above error.

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.

Expected behavior App should save the given secret to Azure vault.

Actual behavior (include Exception or Stack Trace) SetSecretAsync fails with the above exception

Previously I had following error too and I solved after upgrading Azure.Security.KeyVault.Secrets to v 4.2.0

Method not found: ‘System.Text.Json.JsonEncodedText System.Text.Json.JsonEncodedText.Encode(System.String, System.Text.Encodings.Web.JavaScriptEncoder)’.

To Reproduce

string vaultUrl = MyUrls.ConnectorKeyVaultUrl;

var client = new SecretClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());

result = await client.SetSecretAsync(key, value);

Environment:

<PackageReference Include="JWT" Version="8.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Azure.Identity" Version="1.4.1" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
  • Mac OS - .Net Core 3.1
  • IDE and version : [e.g. Visual Studio mac 16.3]

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (8 by maintainers)

Most upvoted comments

Hi, we’re sending this friendly reminder because we haven’t heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don’t hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

I’m assuming you mean “functions”, but can you clarify what the “functions app” is? Are you talking about the Azure Functions SDK / test host? Did you try updating to the latest Azure Functions SDK or do any host logging?

The Key Vault SDK - all our latest SDKs, actually - will automatically pull in a new versions, but if the host application is ignoring that DLL and loading an older version (which has a security vulnerability), the host application needs to be updated.

Thank you for your feedback. Tagging and routing to the team member best able to assist.