Azure function fails to create Microsoft.Extensions.Logging.Abstractions.dll after .net5 upgrade

Total
17
Shares

As part of a WebApi app upgrade, I upgraded an Azure function from .Netcore 2 to .Net5. This function has previously worked. When I run the function, I get the following error:

System.Private.CoreLib: Could not load file or assembly ‘Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. The system cannot find the file specified.

I made the following changes to the function project as part of the upgrade:

  • Changed Project file TargetFramework to .net5.0
  • Changed AzureFunctionsVersion to v3
  • Upgraded the referenced packages
    • Microsoft.Azure.WebJobs
    • Microsoft.Azure.WebJobs.Extensions.EventGrid
    • Microsoft.Azure.WebJobs.Extensions.Storage
    • Newtonsoft.Json

I changed the Azure function configuration setting for the Runtime Version to ~3.

After getting the above error, I also added the packages

  • Microsoft.Extensions.Logging
  • Microsoft.Extensions.Logging.Abstractions

Building the project with the above references doesn’t create the Microsoft.Extensions.Logging.Abstractions.dll in the .Net5 bin directory. Note that I do see that dll in the bin directory of the .Netcore 2 build. Why am I not seeing the dll when building for .Net5?

Functions.csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.27" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.4" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.12" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..VI.VirtualIncision.ManagersVI.VirtualIncision.Managers.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="appsettings.json">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

Solution

Based on your packages (i.e. Microsoft.Azure.WebJobs) and your csproj file it looks like you are currently running an "in-process Azure Function", and .NET 5 is not supported for these types of Azure Functions, so that is why you are getting that error. So you have 3 options:

  1. Based on this Microsoft blog post, it looks like Microsoft is planning on skipping.NET 5 and just adds support for .NET 6 to in-process Azure functions. So you can just wait for .NET 6.
  2. You can try to switch your Azure Function to be a .NET Isolated Process Function which is more involved than just simply updating some packages and changing the target framework. It requires some major changes to how your project is setup and what nuget packages you are using. Microsoft has a guide around this here: https://docs.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide
  3. You can also just downgrade your Microsoft packages to 3.x.x version and keep everything .NET Core 3.1. You will need to make sure you don’t have any other dependencies that use .NET 5 packages or else you will see a similar issue.
Leave a Reply

Your email address will not be published. Required fields are marked *