Sammy
Sammy

Reputation: 51

Azure function v4 migration. Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral

I'm currently migrating an Azure Function from v2 to Azure Functions v4. I already migrated my project to .NET6 and fixed all the package reference errors. I have in the solution 3 projects which I adjusted to .NET6 and Azure Function v4. For that I edited the .csproj files of each of those projects and upgraded/substituted packages which are not working with .NET6. The project file of each project looks like:

Azure Function Project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
      <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
      <PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
      <PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
      <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
      <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />
      <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
      <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
      <PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.0" />
      <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
      <PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
      <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\PCM.1.z\x.1.z.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="2.cs">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Compile>
    <Compile Update="1.cs">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Compile>
    <Compile Update="3.cs">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Second Project:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
      <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.1" />
      <PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.5" />
      <PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
      <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
      <PackageReference Include="Microsoft.Azure.Devices" Version="1.38.2" />
      <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.33" />
      <PackageReference Include="SendGrid" Version="9.28.1" />
      <PackageReference Include="StackExchange.Redis" Version="2.6.80" />
      <PackageReference Include="Twilio" Version="6.0.1" />
      <PackageReference Include="UnitsNet" Version="4.149.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\x.1.w\x.1.w.csproj" />
  </ItemGroup>

</Project>

Third Project:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
  </ItemGroup>

</Project>

When I build the project I got no errors. But when I debug the project I got an exception which looks like:

Exception:

Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Azure.WebJobs.Host.dll. An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Azure.WebJobs.Host.dll but was not handled in user code Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

I have tried the last two weeks different packages since when I googled this error, the suggestion was to see which packages are not supported by package: <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />. I analyzed all my packages. After changing them back and force I got still the same error.

Can anyone help me and say what exactly I have to change?

Upvotes: 5

Views: 10076

Answers (6)

reim
reim

Reputation: 612

Encountered this issue when trying out this example. Downgrading a few Azure dependencies here and there eventually solved the issue.

Upvotes: 0

b_levitt
b_levitt

Reputation: 7415

TLDR:

Upgrading my functions to v4/.net7/dotnet-isolated finally fixed it for me. Reviewing a fresh Azure Function (dotnet-isolated) project was also very helpful (Program.cs changes, ILogger to ILoggerFactory changes, etc)

Full Version:

During my fight with this issue I could certainly see that the dll in question is excluded from the bin folder but is in the lib folder. Copying the dll manually did get me passed that one error I believe, but I think I just ran into another one. Plus a manual copy step would have been pretty dirty.

Here's what didn't work for me:

  • Including the package in the top level function application
  • Downgrading the package (I didn't go below 6 though)
  • Including _FunctionsSkipCleanOutput in the csproj file
  • Downgrading the project to .net 6

Part of this might have been me not realizing that .net 7 supports ONLY the isolated model but I still never got it to work under .net 6. But there were a lot of advantages anyway going to the isolated model, including the DownstreamApi middleware working right out of the box without a custom ITokenA

Upvotes: 1

voidmain
voidmain

Reputation: 1611

If it helps others, my case was using .NET 6 in-process. Compile was successful, but debug failed with the same message as posted but for version 6.0.0.0. moved past that error by noticing in the debug window the Function Runtime Version was 3.x. I followed the suggestion on this page https://learn.microsoft.com/en-us/azure/azure-functions/migrate-version-3-version-4?pivots=programming-language-csharp&tabs=net6-in-proc%2Cazure-cli%2Cwindows to update the value of project property AzureFunctionsVersion from v3 to v4.

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <RootNamespace>My.Namespace</RootNamespace>
</PropertyGroup>

Upvotes: 0

Sammy
Sammy

Reputation: 51

I fixed it by including the package Microsoft.Extensions.Configuration.Abstractions 6.0.0 and building it. To include this package doesn't solve the problem directly it just shows which packages have a conflict. By downgrading these conflicting packages the project could be debugged. To check which packages are conflicting you have to open up the packages on the right side in visual studio and look where is a exclamation mark. Then you have to analyze these packages to know on what version you have to downgrade them. It changes from project to project.

Upvotes: 0

asymetrixs
asymetrixs

Reputation: 51

I am building an Azure function as v4 in net6. Since I also got the System.IO.FileNotFoundException regarding library Microsoft.Extensions.Configuration.Abstraction 7.0.0 when starting up the function, I downgraded to Microsoft.Extensions.Configuration.Abstractions 6.0.0 and also had to downgrade other dependencies such as Microsoft.EntityFrameworkCore to 6.0.12 and, since I am using PostgreSQL also Npgsql.EntityFrameworkCore.PostgreSQL to 6.0.8. Now everything works.

Upvotes: 1

anon
anon

Reputation:

As @Codebrane said, Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0 has the issues in working with Azure Functions v4 Version and it has been shown practically in this thread.

  • Try by downgrading the Microsoft.Extensions.Configuration.Abstractions to Version 6.0.0 and check.

  • Microsoft.NET.Sdk.Functions depends on the NuGet Packages related to the Code but these can be suggested by VS IntelliSense and installed automatically, or it shows these packages required.

  • Also, NuGet Packages varies between In-Process and Out-of-Process worker type in Azure Functions. Refer to one of my threads for more information.

Upvotes: 2

Related Questions