'Visual Studio .NET Framework 4.8 - Could not load file or assembly 'Azure.Core, Version=1.20.0.0,

We have a Microsoft Azure Function App in .NET Framework 4.8. We want to retrieve via Managed Identity a document out of our blob.

We're trying the use the following code:

 BlobContainerClient containerClient = new BlobContainerClient(new Uri(containerEndpoint), new DefaultAzureCredential());

                BlobClient blobClient = containerClient.GetBlobClient(mapName);
                var bytes = blobClient.DownloadContent().Value.Content.ToArray();

To make this work we're using nuGet packages:

  1. Azure.Identity (latest version: 1.5.0)
  2. Azure.Storage.Blobs (latest version: 12.11.0) => This needs to work with Azure.Core 1.22.0

Whenever we try to POST a message to our function, we directly receive an error: Could not load file or assembly 'Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.

Adding Azure.Core package version 1.22.0 or 1.20.0 direclty into the project is not helping.

It works if we either use Azure.Identity or Azure.Storage.Blobs, but not when using both.

In the project.assets.json file, we can see a dependency to version Azure.Core 1.20:

  "Azure.Identity/1.5.0": {
        "type": "package",
        "dependencies": {
          "Azure.Core": "1.20.0",
          "Microsoft.Identity.Client": "4.30.1",
          "Microsoft.Identity.Client.Extensions.Msal": "2.18.4",
          "System.Memory": "4.5.4",
          "System.Security.Cryptography.ProtectedData": "4.5.0",
          "System.Text.Json": "4.6.0",
          "System.Threading.Tasks.Extensions": "4.5.4"
        },

Is there any way how we can reference in our Function App to use version 1.22.0 of the Azure.Core package?



Solution 1:[1]

I have solved this previously by modifying the .csproj like below when i get the error Could not load file or assembly 'Azure.Core, Version=1.20.0.0

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net48</TargetFrameworks>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>signingkey.snk</AssemblyOriginatorKeyFile>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  </PropertyGroup>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuryasriKamini-MT