Upgrade my Azure Function from .net Core 3.1 to .net Core 7.0. Error "'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstraction

john john 966 Reputation points
2023-01-27T16:29:45.1233333+00:00

I have an Azure Function which run on .net core 3.1, but when i change the .net version from 3.1 to 7 i got this error:-

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'

here is a screen shot:-

enter image description here

here is my csproj file:-

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
    <PackageReference Include="PnP.Core.Auth" Version="1.8.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Any advice on this please?

I have installed Install-Package Microsoft.Extensions.Configuration.Abstractions -Version 7.0.0 but this did not fix the issue either.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,079 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,603 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,226 Reputation points
    2023-01-30T17:05:16.2333333+00:00

    you are using obsolete nuget packages. try:

    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.10.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.7.0" />
    
    0 comments No comments

  2. Mike Urnun 9,816 Reputation points Microsoft Employee
    2023-01-31T22:16:32.9433333+00:00

    Hello, @john john - Thanks for reaching out and posting on the MS Q&A!

    In addition to the NuGet packages referenced in @Bruce (SqlWork.com) 's answer, your .csproj file is also missing the following;

    <ItemGroup>
      <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
    </ItemGroup>
    

    The complete .csproj file should look like the below:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <RootNamespace>My.Namespace</RootNamespace>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
      </ItemGroup>
      <ItemGroup>
        <None Update="host.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
      </ItemGroup>
      <ItemGroup>
        <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext"/>
      </ItemGroup>
    </Project>
    

    For more details, please review our official doc on this migration:

    • Migrate apps from Azure Functions version 3.x to version 4.x (if you encounter any faulty steps in the doc, please consider opening a doc issue with relevant details using the "This Page" button located at the bottom of the page - and we'd be happy to address the issue with our doc authoring team)

    If the steps in the doc seem valid but you're still hitting different errors, feel free to let me know in the comments as well.

    0 comments No comments

  3. JayK 0 Reputation points
    2023-08-15T15:32:24.5966667+00:00

    Did you find a solution? I have same problem here. All solutions stated above are for isolated functions but as I see you are using in process functions .?

    0 comments No comments

  4. Jagadeesh Gangadhar Junjuri 0 Reputation points
    2024-02-22T16:02:17.3133333+00:00

    same issue is resovled by updating the package to "Microsoft.Azure.Functions.Worker.Sdk" to version "1.16.4" only

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.