4

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?

Sammy
  • 41
  • 1
  • 3
  • "Version=7.0.0.0". I had lots of problems when upgrading when this version was proposed by VisualStudio. I would get those errors as 7.0.0.0 relies on .net7 whereas my functions are .net6 in Azure. I had to delete the bin/ and obj/ directories to get rid of the errors and clean/rebuild all. Not deleting those directories and the errors persisted even after moving down a version. This might help https://stackoverflow.com/questions/74368240/microsoft-extensions-x-version-7-0-0-issue-net-7-functionapp – codebrane Dec 09 '22 at 15:53
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Dec 10 '22 at 15:09

5 Answers5

2

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.

  • Hi @Hari. What exactly do you mean by downgrade Microsoft.Extensions.Configuration.Abstractions to Version 6.0.0? Since I don't have that package in my .csproj file declared. When I declare it then it cant even build with the error: Error NU1605 Detected package downgrade: **Microsoft.Extensions.Configuration.Abstractions from 7.0.0 to 6.0.0. Reference the package directly from the project to select a different version.** – Sammy Dec 12 '22 at 12:18
  • As you have mentioned could not load file or assembly the `Microsoft.Extensions.Configuration.Abstractions` package –  Dec 12 '22 at 12:22
  • 2
    I was unable to downgrade it to 6.0.0. , due to dependency issue @Sammy, if you have fixed it, please update the answer – ispostback Dec 15 '22 at 12:43
1

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.

asymetrixs
  • 51
  • 5
0

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.

Sammy
  • 41
  • 1
  • 3
0

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>
voidmain
  • 1,521
  • 1
  • 12
  • 14
0

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

b_levitt
  • 7,059
  • 2
  • 41
  • 56