skip to Main Content

I recently upgraded an Azure Function App from .NET 6 to .NET 8 and encountered an issue during local execution. The project compiles successfully, but when running it locally, I face the following assembly loading error:

function is in error: Could not load file or assembly
‘Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0

This problem seems to relate to Microsoft.Extensions.Logging.Abstractions and appears to be a common issue with .NET 8 based on my research and similar issues reported on Stack Overflow:

Azure Function in .Net 6 giving error Could not load file or assembly

and

Could not load file or assembly Microsoft.Extensions.Logging.Abstractions

Downgrading to .NET 6 is not an option for me, as other projects in the solution that the Function App depends on have been upgraded to .NET 8, and reverting those changes would lead to compatibility issues.

I came across the concept of "Isolated Mode" in Azure Functions, which seems like it might be a solution to my problem, but I’m unsure how to implement it in my current setup or if it’s even the right approach.

Here’s the project file (*.csproj) for my Function App:

This is the project file of the fuction app:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <DockerFastModeProjectMountDirectory>/home/site/wwwroot</DockerFastModeProjectMountDirectory>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.10.4" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.17.1" />
    <PackageReference Include="Azure.Storage.Queues" Version="12.17.1" />
    <PackageReference Include="Microsoft.AspNetCore.AzureKeyVault.HostingStartup" Version="2.0.4" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.2.2" />
    <PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.3.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
    <PackageReference Include="SendGrid" Version="9.28.1" />
  </ItemGroup>
  <ItemGroup>

    //These Projects are now .net 8.0
    <ProjectReference Include="..AsoRockFood.com.Umbraco.ModelsAsoRockFood.com.Umbraco.Models.csproj" />
    <ProjectReference Include="..RockLife.ServicesAsoRockFood.com.Services.csproj" />

  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

How can I resolve the assembly loading error without downgrading my .NET version?

Is switching to Isolated Mode a viable solution? If so, how should I go about implementing it in my Function App?

Any insights or suggestions would be greatly appreciated.

Thank you in advance!

2

Answers


  1. Chosen as BEST ANSWER

    I have discovered a solution - For those upgrading from an earlier version of .NET to .NET 8 for Azure Function Apps:

    Opt for the isolated worker model. It offers more flexibility with .NET versions in relation to the project's dependencies.

    When upgrading an Azure Function App to .NET 8, there are several modifications you need to make to your application code. Simply upgrading the NuGet package is not sufficient.

    This is a very useful guide: Migrate .NET Azure functions to the isolated model.

    https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8

    Essentially my problem was I just upgraded the Nuget package and hoped for the best. - Read the docs, you have to make a lot of changes to your code to get this to work.


  2. First of all, one thing you touch on is that you are using the in-process model. .Net 8 ONLY supports isolated.
    msoft table
    https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=windows

    Secondly, this issue can happen when a project reference is using a version of the package that is older. Check the referenced packages to make sure they are using the same version of Microsoft.Extensions.Logging.Abstractions

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search