2

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?

  • What error means is the Net Version of Library and the version of the library in the proj file do not match. The easiest way of fixing issue is to use VS Solution Explorer and in References delete the current reference and then add the reference back to project which is automatically get the version from Net installed. Sometimes the error is caused by the intermediate obj files not getting compiled and doing a clean build will fix issue. – jdweng Mar 18 '22 at 14:24
  • Unfortunately removing and re-adding the versions/ nuget packages did not work. Also not the sequence in adding the packages. They always start complaining about the references Azure.Core package. – Bart Verellen Mar 21 '22 at 10:12
  • The Azure Core dll should be in your bin folder. Normally when you add a project to another project you browser to the bin debug folder of the project you are adding. Then when you compile the latest dll from the other project is copied into your project bin folder. – jdweng Mar 21 '22 at 11:53
  • I'm unsure about the steps which I need to take. I removed all packages, deleted the complete obj and bin folder, re-added via nuget the packages Azure.Identity and Azure.Storage.Blobs, but the error persists. I started a fresh solution from scratch and recreated the function app, but the same error pops up. – Bart Verellen Mar 22 '22 at 12:35
  • Try following : https://stackoverflow.com/questions/70585425/how-to-resolve-could-not-load-file-or-assembly-azure-core?force_isolation=true – jdweng Mar 22 '22 at 12:47

1 Answers1

0

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>